如何组合两个 JSON 字符串存储在数据库中
我有以下数据,这些数据实际上应该是一个 JSON 字符串,但我不确定将两者组合成一个有效的 JSON 字符串。我认为睡眠不足使我无法正常思考。
{“0”:{“a”:“22”,“b”:“44”,“b”:“77”}} {“1”:{“a”:“2200”,“b”:“4400”,“c”:“7700”}}
我真的希望它是这样的:
{“0”:{“a”: "22","b":"44","b":"77"},"1":{"a":"2200","b":"4400","c":"7700"} (我假设这是一个有效的 JSON 字符串
I have the following data that really should be one JSON string however I am not sure to combine the two into a valid JSON string. I think lack of sleep is making me not think properly.
{"0":{"a":"22","b":"44","b":"77"}}
{"1":{"a":"2200","b":"4400","c":"7700"}}
I really want it to be something like:
{"0":{"a":"22","b":"44","b":"77"}, "1":{"a":"2200","b":"4400","c":"7700"}} (i am assuming this is a valid JSON string
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果我理解你的问题, http://jsfiddle.net/4S2wC/ 应该是你要找的正确地
http://jsfiddle.net/4S2wC/ should be what you're looking for, if I understand your question correctly
for (var foo in bar)
循环一个对象的所有属性,并复制到另一个对象for (var foo in bar)
to loop over all the properties of one object, and copy to the other object您可以尝试使用正则表达式,例如:
这对对象图的深度和语法做出了一些假设。
You could try a regex such as:
This makes some assumptions around the depth of the object graph and the syntax.
下面的函数有助于组合 json 对象。
你可以像最后那样形成json字符串,
我想你想要js。我们可以使用 javascript 使其具有相同的结构..
使用数组而不是 JsonObject..
我希望它对您有帮助
Below function is helps to combine the json object.
You can form the json string like that at end
I think you want to js. We can make it same Structure using javascripts..
Using array instead of JsonObject..
I hope its help to you
为什么人们总是创建自己的功能,这真的超出了我的理解。
有很多功能可供您使用,为什么不使用它们呢?
Jquery 有一些非常好的函数,例如
$.extend({},j1,j2)
http://api.jquery.com/jQuery.extend/$.merge( [0,1,2], [2,3,4] )
对于数组边距 http://api.jquery.com/jQuery.merge/Why people create their own function always, it's really out of my mind.
There are lot's of functions out there for you, why not use those?
Jquery has some really good functions about these, like
$.extend({},j1,j2)
http://api.jquery.com/jQuery.extend/$.merge( [0,1,2], [2,3,4] )
for array marge http://api.jquery.com/jQuery.merge/