1
我从用户获取JSON和JSONPath。用户还给我一个他想添加到他的JSON中的新内容(值或对象)。我试图创建一个方法,将新的内容添加到JSONPath指定的路径。通过JSONPath在指定位置添加JSON
方法输入:JSON,jsonpath,newcontent(字符串) 方法输出:具有添加newcontent
JSON例如
{ "store": {
"book": [
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
}
]
}
}
JSONPath例如
$.store
新JSON 要添加的对象
movie [title : The Godfather]
方法返回
{ "store": {
"book": [
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
}
],
"movie": [
{
"title" : "The Godfather"
}
]
}
}
谢谢你的提示,我知道这样 - 但数据哪个用户希望添加将会动态改变。 –
@JamesTheEvangelist,这个数据是如何指定的?你可以轻松解析它到一个有效的JSON对象吗? –
用户给我一个JSON格式的数据(他想要添加的)。防爆。 ''电影“:[ { ”title“:”sometitle“ } ] '或''title”:“sometitle”'数据可以有其他值。那些书和电影只是一个例子:)。 –