java - android中如何解析json字符串

标签 java android eclipse json httpresponse

我是 Android 新手。我对 Android 中的 JSON 解析有所了解。我正在解析一个 Twitter feed,我想解析名为“user”的标签,其中包含 profile_image_urlscreen_name

JSON 源是 here 。这是我的代码:

JSONParser jParser = new JSONParser();

// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);

try {
    // Getting Array of Contacts

    contacts = json.getJSONArray(USER);

    // looping through All Contacts
    for(int i = 0; i < contacts.length(); i++){
        JSONObject c = contacts.getJSONObject(i);
    }

最佳答案

您可以使用JSONObject在安卓中。

    JSONParser jParser = new JSONParser();

    // getting JSON string from URL
    String jsonString = jParser.getJSONFromUrl(url).tostring();

    JSONArray json= new JSONArray(jsonString);



    try {

        // looping through All Contacts
            for(int i = 0; i < json.length(); i++){
              JSONObject contacts = json.getJSONObject(i);

                JSONObject user = contacts.getJSONObject("user");

                String imageUrl = user.getString("profile_image_url");
                String screenName = user.getString("Screen_name");

            }
        }catch(Exception e)
   {
   }

关于java - android中如何解析json字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12165015/

相关文章:

python - eclipse /PyDev : Sync System PYTHONPATH runs continuously

eclipse - 如何让 Eclipse/EPIC 停止在我的 Perl 脚本中发出有关 "Use of uninitialized value $ENV{whatever}"的警告?

java - 您的 PreferenceActivity 实现容易受到 fragment 注入(inject)的影响

java - Dozer 是否允许从 Enum 转换为 Enum?

android - Android 中的上传和下载速率分析

android - 在 `onResume` 方法之后更改区域设置不起作用?

java - Vaadin QuickTickets 仪表板部署错误

java - Flux.generate(...) 的预加载元素

Java 密码 NoSuchPaddingException

android - Build-it ListView是透明的——如何设置不透明?