Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 简单JSON服务器_Java_Android_Json_Parsing - Fatal编程技术网

Java 简单JSON服务器

Java 简单JSON服务器,java,android,json,parsing,Java,Android,Json,Parsing,如何在android中解析这种类型的json: { "chatCircles": [{ "id": "59660c155d44f20b46eab438", "name": "Hyderabad Circle", "description": "Hyderabad" }] } 我已经尝试过了,但是UI没有更新 try { JSONArray chatCircleArray = response.getJSONArray("chatCircle");

如何在android中解析这种类型的json:

{
"chatCircles": [{
    "id": "59660c155d44f20b46eab438",
    "name": "Hyderabad Circle",
    "description": "Hyderabad"
}]
}
我已经尝试过了,但是UI没有更新

try {
        JSONArray chatCircleArray = response.getJSONArray("chatCircle");
        for (int i = 0; i < chatCircleArray.length(); i++){
           JSONObject geoFenceObject = chatCircleArray.getJSONObject(i);
           circleId = geoFenceObject.getString("id");
           String circleName = geoFenceObject.getString("name");
           String location = geoFenceObject.getString("description");
           Log.d(TAG, "GeoFenceObject Chat Circle Id parsed is:\t " + circleId);
           System.out.println("Chat Circle id is: \t" + circleId);

            } catch (JSONException e) {
                e.printStackTrace();
            }
试试看{
JSONArray chatcirclarray=response.getJSONArray(“聊天圈”);
对于(int i=0;i

请帮助。如何进行json解析?

第一个大括号是您没有解析的JSONObject。 请尝试下面的代码

try {
        JSONObject json = new JSONObject(response);

        JSONArray itemArray = json.getJSONArray("chatCircles");
        for (int i = 0; i < itemArray.length(); i++) {
            JSONObject subJson = (JSONObject) itemArray.get(i);
            String id = subJson.getString("id");
            String name = subJson.getString("name");
            String description = subJson.getString("description");
            Log.i("TEST", "id=" + id + ", name=" + name + ", description=" + description);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
试试看{
JSONObject json=新的JSONObject(响应);
JSONArray itemArray=json.getJSONArray(“聊天圈”);
对于(int i=0;i
getJSONArray(“聊天圈”);
..?你是说
getJSONArray(“聊天圈”);
?是的,非常感谢你这么做了。现在需要更加小心。谢谢大家