java - Parse JSON URL - JSONException Error -


please give me hand here, trying parse json file url. below code used grab file , posted textview want parse tags , use them?

private void postdata(final string param, final textview tv) {      final requestqueue request = volley.newrequestqueue(this);      jsonobject postreq = new jsonobject(request.method.get, url_login, new response.listener<jsonobject>() {          @override         public void onresponse(jsonobject response) {          }     }, new response.errorlistener() {          @override         public void onerrorresponse(volleyerror error) {             system.out.println("error [" + error + "]");          }     }) {          @override         public map getheaders() throws authfailureerror {             map headers = new hashmap();             headers.put("accept", "application/json");             system.out.println(headers);             return headers;         }     };     request.add(postreq); } 

an example of json below

{ “userinfo”: {     “user”: {         “name”: “craig”,         “surname”: "churchill",         "userid": "1463353",         "useralias": "craig"     }   } } 

i have tried this have failed , cannot right.

enter image description here

{     "userinfo": {         "user": {             "name": "craig",             "surname": "churchill",             "userid": "1463353",             "useralias": "craig"         }     } } 

it´s valid json. i´ve tried on http://jsonlint.com/ you've got double commas have weird encoding. put json above right doble comma enconding, since jsonlint giving errors validating json until changed them.

the problem might on how you're accesing object , it´s childrens. try way.

@override public void onresponse(jsonobject response) {     try {         jsonobject userobj = response.getjsonobject("userinfo")                             .getjsonobject("user");         string name = userobj.getstring("name");         ...     } catch (jsonexception jsex) {         jsex.printstacktrace();     }  } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -