Using JSON in PHP to send data to Android -


i'm not sure json codes have used in php right send data android app. android app works fine without errors. i'm using async task retrieve information server using json.

this code have used in android app information server :

jsonarray arr = new jsonarray(result); jsonobject jobj = arr.getjsonobject(0); myoutput = jobj.getstring("stringpval"); 

i havn't displayed entire code, i'm sure other codes work fine.

and below php script used create json array in php:

$a = array( array('stringpval' => "my value")); print $json = json_encode($a); 

so have finished encoding json. want textview in android display "my value"! when run android app , try information server, textview goes blank. null! what's problem? solution? above codes correctly used?

the reason json_encode($a); returning jsonobject , not jsonarray you're thinking.

what you're printing this:

{     {         'stringpval' = "my value"     } } 

i'm not sure why you're using double-array passing single value that, change php file to:

$a = array('stringpval' => "my value"); print $json = json_encode($a); 

which return:

{     'stringpval' = "my value" } 

which access in java by:

jsonobject jobj = new jsonobject(result); myoutput = jobj.getstring("stringpval"); 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -