如何从Json对象获取数据?
我正在与集成的android应用程序上工作。我正在使用fql查询从Facebook获取信息。我的fql方法是
void runfql(){ String fqlQuery = "SELECT uid, name, pic_small,birthday FROM user WHERE uid IN " +
"(SELECT uid2 FROM friend WHERE uid1 = me() )";
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Session session = Session.getActiveSession();
Request request = new Request(session,
"/fql",
params,
HttpMethod.GET,
new Request.Callback(){
public void onCompleted(Response response) {
JSONObject myjson=response.getGraphObject().getInnerJSONObject();
Log.d("ResultResultResult: " ,""+myjson);
}
});
Request.executeBatchAsync(request);
}
myjson对象具有我想要的所有信息。像这样
{"data":[{"uid":536089174,"birthday":"July 22","name":"Usman Aslam Sheikh"},{"uid":581379174,"birthday":"July 26","name":"Ammar Khalid"}
问题是如何将该信息存储到不同的阵列中?
请为此修改一些代码。
回答:
String jsonString = yourstring;JSONObject jsonResult = new JSONObject(jsonString);
JSONArray data = jsonResult.getJSONArray("data");
if(data != null) {
String[] names = new String[data.length()];
String[] birthdays = new String[data.length()];
for(int i = 0 ; i < data.length() ; i++) {
birthdays[i] = data.getString("birthday");
names[i] = data.getString("name");
}
}
检查http://www.androidhive.info/2012/01/android-json-parsing-
tutorial/
以上是 如何从Json对象获取数据? 的全部内容, 来源链接: utcz.com/qa/406738.html