简体   繁体   English

如何从多组键值对中编辑json数据

[英]How to edit json data from multiple sets of key value pair

How can we modify json data from multiple data(like value from any key value pair) in java?我们如何从 java 中的多个数据(如来自任何键值对的值)修改 json 数据?

A "JSON object" is actually an oxymoron. “JSON 对象”实际上是一个矛盾词。 JSON is a text format describing an object, not an actual object, so data can either be in the form of JSON, or deserialised into an object. JSON 是描述 object 的文本格式,而不是实际的 object,因此数据可以采用 JSON 的形式,也可以反序列化为 object。

Once you have parsed the JSON into a Javascript object (called data in the code below), you can for example access the object for KEY2 and it's properties like this:将 JSON 解析为 Javascript object(在下面的代码中称为数据)后,您可以访问 object 以获取 KEY2 及其属性,如下所示:

var obj = data.KEY2;
alert(obj.NAME);
alert(obj.VALUE);

If you have the key as a string, you can use index notation:如果您将键作为字符串,则可以使用索引表示法:

var key = 'KEY3';
var obj = data[key];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM