java - how to parse this in android with json -
i want parse json in android. can me how parse, if need start head parse or results don't know. can me
{ "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" } } ] } }
okay, first of json string you've given invalid. i've written answer based on correct version of json string have provided
{ "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" } } ] } }
now, "values", you'll need this.
jsonobject jsonobject = new jsonobject(response); jsonobject results = jsonobject.getjsonobject("results"); jsonarray bindings = results.getjsonarray("bindings"); (int = 0; < bindings.length(); i++) { jsonobject binding = bindings.getjsonobject(i); jsonobject city = binding.getjsonobject("city"); // value in city string cityvalue = city.getstring("value"); log.d("city", cityvalue); jsonobject country = binding.getjsonobject("country"); // value in country string countryvalue = country.getstring("value"); log.d("country", countryvalue); }
Comments
Post a Comment