我有以下JSON文本.如何可以解析它来获得pageName,pagePic,post_id,等?
{
"pageInfo": {
"pageName": "abc",
"pagePic": "http://example.com/content.jpg"
},
"posts": [
{
"post_id": "123456789012_123456789012",
"actor_id": "1234567890",
"picOfPersonWhoPosted": "http://example.com/photo.jpg",
"nameOfPersonWhoPosted": "Jane Doe",
"message": "Sounds cool. Can't wait to see it!",
"likesCount": "2",
"comments": [],
"timeOfPost": "1234567890"
}
]
}
Run Code Online (Sandbox Code Playgroud) 我有一个名为String的变量jsonString:
{"phonetype":"N95","cat":"WP"}
Run Code Online (Sandbox Code Playgroud)
现在我想将其转换为JSON对象.我在Google上搜索得更多,但没有得到任何预期的答案......
Stackoverflow中有很多示例来展示如何解析JSON。但是没有一个例子对我有用,我想我有一个普遍的问题,我不明白:
我在以下陈述中得到一个错误:
JSONObject obj2 = new JSONObject("{interests : [{interestKey:Dogs}, {interestKey:Cats}]}");
Run Code Online (Sandbox Code Playgroud)
例外:
Exception in thread "main" java.lang.RuntimeException: Stub!
at org.json.JSONObject.<init>(JSONObject.java:7)
at JSONTest.main(JSONTest.java:44)
Run Code Online (Sandbox Code Playgroud)
我正在使用Java 1.7和库org.json
可能是什么原因 ?
我有以下字符串: ["LankaBell","BillDesk"]
如何使用json-lib-2.2.3-jdk15.jar\net\sf\json库将其转换为Java列表对象?
编辑:如果不能使用此库,那么使用其他库的解决方案也很受欢迎.