I am newbie to json.I am trying to read values from MySQL database and encode the result to json data.for that i have written following coding
<?php
$conn=mysql_connect('localhost','root','');
$mydb=mysql_select_db("json",$conn) or die('failed');
$result=mysql_query("select * from register",$conn);
$rowsarray[]=array();
$rowsarra[]=null;
while($rows=mysql_fetch_assoc($result)){
$rowsarray[]=$rows;}
echo json_encode($rowsarray); ?>
i am getting output as
[[],{"name":"$name","password":"$password","email":"$email","address":"$address"},{"name":"rushi","password":"dfsdf","email":"dsfgs","address":"ssfsfsdf"},{"name":"hmd","password":"123","email":"rdf","address":"sfdssf"},{"name":"sdfs","password":"sdfsf","email":"sdfsdf","address":"sdf"},{"name":"rushi","password":"sadsa","email":"xdfsaf","address":"sdfsdf"}]
when i view this in online jsonviewer i get the output as +JSON
+0 +1 +2 +3 +4 +5how can i read the details inside the json object for '0','1',... in my android application
JsonArray jsonarray=new JsonArray(response.tostring);
JsonObject job=jsonarray.getstring("0");
is this the way to get the jsonobject? (or)
how can i give employee email in place of 0,1,2,... please help me out. if i am wrong anywhere please correct me. Thanks in advance