JSONObject jsonObject = new JSONObject(s);
然後用Iterator迭代器遍歷取值,建議用反射機制解析到封裝好的對象中
JSONObject jsonObject = new JSONObject(jsonString); Iterator iterator = jsonObject.keys(); while(iterator.hasNext()){ key = (String) iterator.next(); value = jsonObject.getString(key);
}
如果還想獲得key 值:
JSONObject rawJson = JSONObject.parseObject(jsonString);
Set<String> set = jsonObject.keySet();
for (String key : set) {
rawJson.fluentPut(key, jsonObject.get(key).toString());//放入rawjson對象中
}