json字符串格式:
{
"RetValue": "1",
"RetMessage": "suc",
"links": [
{
"name": "Google",
"url": "http://www.google.com"
},
{
"name": "Baidu",
"url": "http://www.baidu.com"
}
]
}
java代码:用的阿里的fastjson包,com.alibaba.fastjson.JSONObject;
String strRet = "{'RetValue': '1','RetMessage': 'suc',"
+ "'links': ["
+ " {"
+ " 'name': 'Google',"
+ " 'url': 'http://www.google.com'"
+ " },"
+ " {"
+ " 'name': 'Baidu',"
+ " 'url': 'http://www.baidu.com'"
+ " }"
+ " ]"
+ "}";
JSONObject jsonObject = JSONObject.parseObject(strRet);
Map<String,Object> map = (Map<String,Object>)jsonObject;
String retValue = (String) map.get("RetValue");
System.out.println("retValue的值是"+retValue);
Object links= map.get("links");
List<Link> list = JSONObject.parseArray(links.toString(), Link.class);