我上传了一个json
文件到我的服务器。这是json file但是当我想分析它,它提供了以下错误:从服务器解析json文件
Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
我应该在服务器做哪些设置?我只设置了MIME
。
,您可以查看我的代码here
我上传了一个json
文件到我的服务器。这是json file但是当我想分析它,它提供了以下错误:从服务器解析json文件
Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
我应该在服务器做哪些设置?我只设置了MIME
。
,您可以查看我的代码here
例如响应:您收到的字符串响应后
{"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"}]}
相当于代码来解析。
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);
?>
我已经做到了,你看到我的代码http://stackoverflow.com/questions/20574800/populate-listview-with-json-parser – samira
哦,我明白了!一旦你从服务器得到的响应不完全是json数据,它就发生在我身上。我的情况是,当我试图使用feedburner将第三方网站的XML feed转换为JSON时。对不起,我没有;在开始时没有注意到<!DOCTYPE标签。我使用PHP来创建它的无痛服务web服务 echo json_encode($ var);对我来说,这个技巧 看到编辑使用PHP代理可能的解决方案。 –
你能打印你的回应吗?最好在这里添加你的代码。 – SilentKiller
从logcat发布你的json响应 – Raghunandan