parsing json file from server

杀马特。学长 韩版系。学妹 提交于 2019-12-02 19:17:36

问题


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.

You can review my codes here


回答1:


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);      
?>


来源:https://stackoverflow.com/questions/20580267/parsing-json-file-from-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!