parsing json file from server

2019-03-04 06:35发布

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.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject

which setting should I do in server? I only set MIME. enter image description here

You can review my codes here

1条回答
你好瞎i
2楼-- · 2019-03-04 07:21

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);      
?>
查看更多
登录 后发表回答