php - Error: java.lang.string cannot be converted to jsonobject -


an error said java.lang.string cannot converted jsonobject, how can convert jsonobject

here php code:

<?php mysql_connect("localhost","root","");  mysql_select_db("mydatabase");      $query = "select sum(orderprice) total tbl_user"; $result = mysql_query($query);   while($row = mysql_fetch_assoc($result)) { $new_arr[] = $row['total']; } echo json_encode($new_arr);  ?> 

my android code:

                try{                     jsonarray jarray = new jsonarray(result);                     for(int i=0;i<jarray.length();i++){                         jsonobject json_data =     jarray.getjsonobject(i);                          log.i("log_tag","total: "+json_data.getstring("total"));                          total.settext("total");                          }                 }catch(jsonexception e){                     log.e("log_tag", "error parsing data " + e.tostring()); 

in below line of code result getting string not formatted in json that's why getting error :

jsonarray jarray = new jsonarray(result); 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -