2

How to store string containing nested Json object in a proper tree format

sample string:

152#233.69#-191.7#133.69#-199.769#AP#4#"{""pot"":4}"#TP#"{""Dp"":12345}" 1581#233.69#-191.7#133.69#-199.769#4#"{""pt"":4,""oil"":{""1"":""HP""}}"#UP#"{""Dp"":67890}" 16849#343.69#-291.8#133.69#-389.769#AMULL#4#"{""sport"":4,""oi"":{""1"":""LT""}}"#null#"{""Dis"":67990}"

each value is separated by # and the values maybe string representation of nested JSON objects

My code:

var myNewLine = arrayOne[i].split('#');
for (var j = 0; j < noOfCol; j++) {
        var temp;
        var headerText = header[j].substring(0, header[j].length);
        valueText = myNewLine[j].substring(0, myNewLine[j].length);
        obj[headerText] = valueText;
     }
    jArray.push(obj);
}
jsonObject = JSON.parse(JSON.stringify(jArray));
 return jsonObject;
2

2 Answers 2

2

Get your data in JSON format and use .update or .set to save it to the Realtime Database. You can use the function below

function update(node,key,value){
    var ref = firebase.database().ref('/');
    var obj = {};
    obj[key] = value;
    ref.child(node).update(obj)
    .then(function() {
        console.log('Update Ran Successfully');
    });       
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Ron Royston
1

For of the string you are passing to the JSON.parse is not correct. Replace two double quotes by single double quote.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.