FastJSON解析JSON的数据的有关问题?
FastJSON解析JSON的数据的问题???
现有JSON数据如下,保存在String变量中:
String mystr =
{
"www.ABC.com": {
"web-servers": [
"Apache"
],
"cache-tools": [
"WordPress Super Cache"
],
"javascript-frameworks": [
"jQuery"
],
"web-frameworks": [
"Twitter Bootstrap"
]
}
}
小白请教大牛:
如何获得web-servers=Apache javascript-frameworks=jQuery
请务必使用FastJSON
------解决思路----------------------
输出 :
Apache
jQuery
现有JSON数据如下,保存在String变量中:
String mystr =
{
"www.ABC.com": {
"web-servers": [
"Apache"
],
"cache-tools": [
"WordPress Super Cache"
],
"javascript-frameworks": [
"jQuery"
],
"web-frameworks": [
"Twitter Bootstrap"
]
}
}
小白请教大牛:
如何获得web-servers=Apache javascript-frameworks=jQuery
请务必使用FastJSON
------解决思路----------------------
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
public class Snippet {
public static void main(String[] args) {
String mystr = " {" + "\"www.freebuf.com\": {\"web-servers\": [\"Apache\"],\"cache-tools\": ["
+ "\"WordPress Super Cache\"]," + "\"javascript-frameworks\": [\"jQuery\"],\"web-frameworks\": ["
+ "\"Twitter Bootstrap\"" + "]}}";
JSONObject po = JSON.parseObject(mystr);
String str = po.getJSONObject("www.freebuf.com").getJSONArray("web-servers").getString(0);
System.out.println(str);
str = po.getJSONObject("www.freebuf.com").getJSONArray("javascript-frameworks").getString(0);
System.out.println(str);
}
}
输出 :
Apache
jQuery