How to store string containing nested Json object in a proper tree format
如何以合适的树格式存储包含嵌套Json对象的字符串
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}"
152 # 233.69 # -191.7 # 133.69 # 233.69 #美联社# 4 #“{”“壶”:4 }”# TP #“{”“Dp ":12345 }”1581 # 233.69 # -191.7 # 133.69 # 233.69 # 4 #“{”“pt”:4,”“油”“:{ " 1 ":“惠普”“} }”#,#“{”“Dp ":67890 }”16849 # 343.69 # -291.8 # 133.69 # 343.69 # AMULL # 4 #“{”“体育”“:4,”“oi ":{“1”“:”“LT”“} }”#空#“{”“说”“:67990 }”
each value is separated by # and the values maybe string representation of nested JSON objects
每个值由#分隔,嵌套的JSON对象的值可能是字符串表示
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 个解决方案
#1
3
Get your data in JSON format and use .update
or .set
to save it to the Realtime Database. You can use the function below
获取JSON格式的数据并使用.update或.set将其保存到实时数据库。您可以使用下面的函数
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');
});
}
#2
1
For of the string you are passing to the JSON.parse is not correct. Replace two double quotes by single double quote.
对于传递给JSON的字符串。解析是不正确的。用单双引号替换两个双引号。
#1
3
Get your data in JSON format and use .update
or .set
to save it to the Realtime Database. You can use the function below
获取JSON格式的数据并使用.update或.set将其保存到实时数据库。您可以使用下面的函数
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');
});
}
#2
1
For of the string you are passing to the JSON.parse is not correct. Replace two double quotes by single double quote.
对于传递给JSON的字符串。解析是不正确的。用单双引号替换两个双引号。