public static void JsonFile(String sJson) throws JSONException{
JSONArray jsonArray = new JSONArray(sJson);
JSONObject jsonObj = jsonArray.getJSONObject(0);
Map<String, Integer> jsonmap = new HashMap<String, Integer>();
// 读取文件内容
jsonmap.put(jsonObj.get("username").toString(),jsonObj.getInt("age"));
}
其中String sJson是你读入的每一条json,最后将结果放入到HashMap中,方便使用。
解析json需要依赖包org.json.jar,然后需要
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
追问这个data数据本来就是用Java从Mysql数据库中提取出来的,然后在Js请求页面时返回的是这个data数据,然后就不知道该怎么处理了。你知道吗?谢谢