parsing json file from server

前端 未结 1 1597

I upload a json file to my server. This is the json file but when I want to parse it, it gives the following error:

Error parsing data org.json.JSO         


        
相关标签:
1条回答
  • 2021-01-28 02:38

    example response:

    {"rows":[{"Fname":"rahim","Lname":"Durosimi","Predictions":"4","Cpredictions":"3","Points":"15"},{"Fname":"Otunba","Lname":"Alagbe","Predictions":"5","Cpredictions":"2","Points":"10"},{"Fname":"Olamide","Lname":"Jolaoso","Predictions":"4","Cpredictions":"2","Points":"10"},{"Fname":"g","Lname":"ade","Predictions":"1","Cpredictions":"1","Points":"5"},{"Fname":"Tiamiyu","Lname":"waliu","Predictions":"1","Cpredictions":"1","Points":"5"}]}
    

    equivalent code to parse after you receive the response in string.

    JSONObject json = new JSONObject(content);          
    JSONArray jArray = json.getJSONArray("rows");
                JSONObject json_data = null;
                for (int i = 0; i < jArray.length(); i++) {
                    json_data = jArray.getJSONObject(i);
                    String fname = json_data.getString("Fname");
    String lname = json_data.getString("Lname");                
       }
    
    
    
    
    <?php
    header('Content-Type: application/json');
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "your url here"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    echo $output = curl_exec($ch); 
    curl_close($ch);      
    ?>
    
    0 讨论(0)
提交回复
热议问题