我在解析 Facebook JSon 数据时遇到问题,我的数据格式是这样的。我在谷歌上搜索了很多时间,但没有得到价值。请建议我如何解决这个问题。您的宝贵答案将不胜感激。
json
{
"id": "",
"name": "",
"first_name": "",
"middle_name": "",
"last_name": "",
"link": "",
"username": "",
"birthday": "",
"location": {
"id": "",
"name": ", "
}
更新 Actullay 我有 https://graph.facebook.com/me?access_token= 获取 session.getAccessToken() 并使其完整 url URL_PREFIX_FRIENDS + session.getAccessToken() 然后发送 url 用于 http 连接并获取 Jsonobject 问题是这个而不是jSonObject 它给出了真正的结果(不知道为什么以及如何)
httpConnection 的代码
public class JsonParsing {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
// constructor
public JsonParsing() {
}
public JSONObject getJSONFromUrl(String url) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
StringBuilder buffer = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(
in, HTTP.UTF_8));
String line = null;
try {
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
json = buffer.toString();
} finally {
in.close();
reader.close();
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
}
之后将其发送到解析器并出现以下错误
日志猫
E/JSON Parser( 5660): Error parsing data org.json.JSONException: Value true of type java.lang.Boolean cannot be converted to JSONObject