JSON的Android:JSON解析 [英] json android: parsing json
本文介绍了JSON的Android:JSON解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个JSON:
[ {user:"John",s:"Ldh",e:"usa"},{user:"Paul",s:"bukit panjang ",e:"FedExForum - Memphis"},{user:"ross",s:"bukit panjang ",e:"FedExForum - Memphis "}]
我用下面的code解析这个检索用户。
I am parsing this with the following code to retrieve all the values of "user" ..
public class ListViewAndroidActivity extends ListActivity {
private String newString, user;
ArrayList<String> results = new ArrayList<String>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TestServiceActivity test = new TestServiceActivity(); //This returns json from the server
newString = test.readPooledFeed(); // returned json in string format
JSONArray rootArray = new JSONArray(newString);
int len = rootArray.length();
for(int i = 0; i < len; ++i) {
JSONObject obj = rootArray.getJSONObject(i);
user = obj.optString("user");
results.add(user);
}
}
这让我没有错误..但没有显示在屏幕上..好心帮!
This gives me no error.. but nothing is shown on the screen .. kindly help!
推荐答案
optString:获取与键关联一个可选的字符串
optString : Get an optional string associated with a key.
我不明白你的JSON对象的关键 U
,它不应该是用户= obj.optString(用户) ;
I don't see the key u
in your JSON object, shouldn't it be user = obj.optString("user");
这篇关于JSON的Android:JSON解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文