gpt4 book ai didi

android - 我无法使用 JSON 解析检索数据

转载 作者:行者123 更新时间:2023-11-30 04:24:58 26 4
gpt4 key购买 nike

{
"user": {
"name": ["bineesh", "Administrator", "binu", "binu", "bijith", "prem"]
},
"email": ["bineesh256@gmail.com", "erpadmin@gmail.com", "binu245@gmail.com", "binu245@gmail.com", "bijith256@gmail.com", "toast@gmail.com"],
"phone": ["7293553814", "12345", "0", "0", "0", "9046567239"]
}

我无法解析这个响应:

Object(result);

// JSONObject jObject;
// jObject= new JSONObject(result);

JSONArray ja = new JSONArray(result);
for (int i = 0; i < ja.length(); i++) {
JSONObject jo = (JSONObject) ja.get(i);
System.out.println(jo.getString("name"));
}

如何在 ListView 中查看此响应?

最佳答案

示例代码:

public class HomeActivity extends ListActivity {

/** Called when the activity is first created. */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, this.fetchTwitterPublicTimeline()));
}

public ArrayList<String> fetchTwitterPublicTimeline()
{
ArrayList<String> listItems = new ArrayList<String>();

try {
URL twitter = new URL(
"http://twitter.com/statuses/public_timeline.json");
URLConnection tc = twitter.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
tc.getInputStream()));

String line;
while ((line = in.readLine()) != null) {
JSONArray ja = new JSONArray(line);

for (int i = 0; i < ja.length(); i++) {
JSONObject jo = (JSONObject) ja.get(i);
listItems.add(jo.getString("text"));
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return listItems;
}
}

关于android - 我无法使用 JSON 解析检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8667370/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com