Java 如何在android中用json解析这个

Java 如何在android中用json解析这个,java,android,json,parsing,Java,Android,Json,Parsing,我想在android中解析这个json。如果我需要从头开始解析,或者从结果开始解析,你能帮助我如何解析吗?我不知道。你能帮我吗 { "head": { "link": [], "vars": ["city", "country"] }, "results": { "distinct": false, "ordered": true, "bindings": [

我想在android中解析这个json。如果我需要从头开始解析,或者从结果开始解析,你能帮助我如何解析吗?我不知道。你能帮我吗

{ 
"head": 
   { 
    "link": [], 
    "vars": ["city", "country"] 
    }, 
"results": 
    { 
        "distinct": false, 
        "ordered": true, 
        "bindings": 
            [ 
                { 
                    "city": 
                        { 
                            "type": "uri",
                             "value": "http://dbpedia.org/resource/Ferizaj"
                        } ,
                    "country": 
                        { 
                        "type": "uri", 
                        "value": "http://dbpedia.org/resource/Kosovo" 
                        }
                 } 
            ] 
    } 
 }

好的,首先,您给出的JSON字符串无效。我已经根据您提供的JSON字符串的正确版本编写了我的答案

 { 
"head": 
   { 
    "link": [], 
    "vars": ["city", "country"] 
    }, 
"results": 
    { 
        "distinct": false, 
        "ordered": true, 
        "bindings": 
            [ 
                { 
                    "city": 
                        { 
                            "type": "uri",
                             "value": "http://dbpedia.org/resource/Ferizaj"
                        } ,
                    "country": 
                        { 
                        "type": "uri", 
                        "value": "http://dbpedia.org/resource/Kosovo" 
                        }
                 } 
            ] 
    } 
 }
现在,要获得这些值,您需要这样做

JSONObject jsonObject = new JSONObject(response);
JSONObject results = jsonObject.getJSONObject("results");
JSONArray bindings = results.getJSONArray("bindings");
for (int i = 0; i < bindings.length(); i++) {
    JSONObject binding = bindings.getJSONObject(i);
    JSONObject city = binding.getJSONObject("city");
    // Get value in city
    String cityValue = city.getString("value");
    Log.d("CITY", cityValue);
    JSONObject country = binding.getJSONObject("country");
    // Get value in country
    String countryValue = country.getString("value");
    Log.d("COUNTRY", countryValue);
}

你能帮我解析这个吗?你想要什么值?值我想要的只是城市和国家的值这个json来自这个链接:我试图用数据库中的sparql查询创建应用程序我复制粘贴那个链接,它说Virtuoso 22023错误请求不包含sparql查询的文本我质疑这个链接,你看到并得到副本,现在没有错误。我需要X中的值和人口、抽象、lat、long和flag来用Androidk解析,我会帮你的。但请将其作为另一个问题发布,因为问题不属于此问题,否则此问题也将被删除。