我怎样才能获得“SEO-MOD-001”的价值?
{
"SEO": [
{
"SEO-MOD-001": {
"SEO-END-001": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
"SEO-END-002": [10, 6, 1, 2, 5, 7, 9, 12, 8, 6, 10, 7]
}
}
]
}
答案 0 :(得分:0)
下载Jar名称Json-simple-1.1.jar
here
将其添加到 lib 或 Maven依赖以及示例代码。
Json Object..
{
"price":100,
"name":"Vikrant Kashyap",
"messages":["lsjdlfj","ljlsdkjfl2","ksdjfljlksd"]
}
将逻辑解析为此对象
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class JsonParsingExample {
public static void main(String[] args) {
JSONParser parser = new JSONParser();
try {
String obj = // this Contains the actual JSON Object as String.
JSONObject jsonObject = (JSONObject) obj;
String name = (String) jsonObject.get("name");
System.out.println(name);
long price= (Long) jsonObject.get("price");
System.out.println(price);
// loop array Message have a array in itself So It must be iterate Using JsonArray Class
JSONArray msg = (JSONArray) jsonObject.get("messages");
Iterator<String> jsonIterator = msg.iterator();
while (jsonIterator .hasNext()) {
System.out.println(iterator.next());
}
} catch (Exception e)
e.printStackTrace();
}
答案 1 :(得分:0)
var data = jQuery.parseJSON('{"SEO": [{"SEO-MOD-001":{"SEO-END-001":["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],"SEO-END-002": [10, 6, 1, 2, 5, 7, 9, 12, 8, 6, 10, 7] }}]}')
data.SEO[0]['SEO-MOD-001']['SEO-END-001']