我有以下网址:
events_value = new URL("https://graph.facebook.com/me/events?access_token="+access_token);
URL 给我以下响应:
我试着把它放到一个 JSONArray 中:
JSONArray jArray = new JSONArray(events_value); //this where the problem comes
final String[] array_spinner = new String[jArray.length()];
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
String jj=json_data.getString("name");
array_spinner[i] = jj;
}
创建数组时不能输入events_value。
请帮忙!
最佳答案
此代码可能对您有所帮助。试试这个。
JSONArray jArray = null;
try {
JSONObject json;
// getting JSON string from URL
if (url != null) {
json = jParser.getJSONFromUrl(url);
System.out.println("reading from url" + json);
}
// Getting Array of jArray
jArray = json.getJSONArray(TAG_NAME);
// looping through All jArray
for (int i = 0; i < jArray.length(); i++) {
JSONObject c = jArray.getJSONObject(i);
Log.d(TAG_TYPE, c.getString(TAG_NAME));//print in log cat
}
} catch (JSONException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
关于android - 将 URL 数据插入 JSONArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13697731/