java - 如何从这个 JSONString 解析?

标签 java android json http

我得到以下 JSONString通过 HTTP Request .我想要所有 amount此字符串中的值。

到目前为止我试过这个:

try {
    // Getting JSON Array
    JSONArray spritPriceArr = jObj.getJSONArray("spritPrice");

    int spritPriceArrLength = spritPriceArr.length();
    for(int i=0; i < spritPriceArrLength; i++ ){

    JSONObject c = spritPriceArr.getJSONObject(i);
    String amount = c.getString("amount");

    System.out.println(amount);
     }

    } catch (JSONException e) {
    e.printStackTrace();
    }

这适用于第一个 spritPrice Array .但是我怎样才能得到amounts其他 spritPrice Array ?

我真的不知道如何实现这一目标。任何人都可以帮助我。

这是我的完整 JSON 字符串的链接:>>This<<

[{"kredit":true,"self":false, “ Sprite 价格” :[{ “金额” :"1.329","datAnounce":"2013-11-27 13:05:07","errorItems":[],"errorCode":0,"datValid":1385553907000,"spritId":"DIE"}] ,"automat":true,"city":"Braunau","open":true,"distance":2.21,"postalCode":"5280","errorItems":[],"priceSearchDisabled":false,"longitude ":"13.0365064","payMethod":"Routex","mail":"","gasStationName":"BP","fax":"","clubCard":"","openingHours":[{"beginn":"06:00","day":{"dayLabel":"Sonntag","order":7,"errorItems":[],"errorCode":0,"day":"SO"}, "end":"22:00"},{"beginn":"06:00","day":{"dayLabel":"Mittwoch","order":3,"errorItems":[],"errorCode ":0,"day":"MI"},"end":"22:00"},{"beginn":"06:00","day":{"dayLabel":"Feiertag","order ":8,"errorItems":[],"errorCode":0,"day":"FE"},"end":"22:00"},{"beginn":"06:00","day ":{"dayLabel":"Montag","order":1,"errorItems":[],"errorCode":0,"day":"MO"},"end":"22:00"}, {"beginn":"06:00","day":{"dayLabel":"Donnerstag","order":4,"errorItems":[],"errorCode":0,"day":"DO"},"end":"22:00"},{"beginn":"06:00","day":{"dayLabel":"Freitag","order":5,"errorItems":[], ” errorCode":0,"day":"FR"},"end":"22:00"},{"beginn":"06:00","day":{"dayLabel":"Samstag","order":6,"errorItems":[],"errorCode":0,"day":"SA"},"end":"22:00"},{"beginn":"06:00","day":{"dayLabel":"Dienstag","order":2,"errorItems":[],"errorCode":0,"day":"DI"},"end":"22:00"} ],"access":"","url":"","serviceText":"gratis Staubsaugen","maestro":true,"companionship":false,"address":"Salzburger Str. 11","club":false,"errorCode":1,"service":false,"latitude":"48.2546591","bar":true,"telephone":""},{"kredit":true, "self":false, "spritPrice" :[{ "金额 ":"1.334","datAnounce":"2013-11-27 12:40:18","errorItems":[],"errorCode":0,"datValid":1385552418000,"spritId":"DIE"} ],"automat":true,"city":"Braunau","open":true,"distance":2.42,"postalCode":"5280","errorItems":[],"priceSearchDisabled":false,"longitude":"13.048711","payMethod":"Novofleet","mail":"office@fetrading.at","gasStationName":"FE-Trading GmbH","fax":"4362467223611","clubCard": "","openingHours":[{"beginn":"06:00","day":{"dayLabel":"Montag","order":1,"errorItems":[],"errorCode":0 ,"day":"MO"},"end":"21:00"},{"beginn":"06:00","day":{"dayLabel":"Donnerstag","order":4 ,"errorItems":[],"errorCode":0,"day":"DO"},"end":"21:00"},{"beginn":"06:00","day":{ "dayLabel":"Dienstag","order":2,"errorItems":[],"errorCode":0,"day":"DI"},"end":"21:00"},{"beginn ":"06:00","day":{"dayLabel":"Samstag","order":6,"errorItems":[],"errorCode":0,"day":"SA"},"end":"21:00"},{"beginn":"08:00","day":{"dayLabel":"Sonntag","order":7,"errorItems":[],"errorCode":0,"day":"SO"},"end":"18:00"},{"beginn":"08:00","day":{ "dayLabel":"Feiertag","order":8,"errorItems":[],"errorCode":0,"day":"FE"},"end":"18:00"},{"beginn ":"06:00","day":{"dayLabel":"Freitag","order":5,"errorItems":[],"errorCode":0,"day":"FR"},"end":"21:00"},{"beginn":"06:00","day":{"dayLabel":"Mittwoch","order":3,"errorItems":[],"errorCode":0,"day":"MI"},"end":"21:00"}],"access":"","url":"http://www.fe-trading.at ","serviceText":"","maestro":true,"companionship":false,"address":"Hofer Straße 1 (\"Hofer Parkplatz\")","club":false,"errorCode":1 ,"service":false,"latitude":"48.244911","bar":false,"telephone":"4362467223634"}]

最佳答案

试试这个,

// ArrayList<String> amountList=new ArrayList<String>();
  String amount=null;
 try {
            // Getting JSON Array
            String your_json_response;
            JSONArray responseArray = new JSONArray(your_json_response);
            for(int j=0;j<responseArray.length();j++)
            {
                JSONArray spritPrice=responseArray.getJSONObject(i).JSONArray("spritPrice");

                int spritPrice= spritPrice.length();

                for(int i=0; i < spritPrice; i++ ){

                  JSONObject c = spritPrice.getJSONObject(i);

                     amount = c.getString("amount");
                     // amountList.add(amount); 
                      System.out.println(amount);
                       if(amount!=null)
                          break;
                    }
                    if(amount!=null)
                      break;
                }
            } catch (JSONException e) {
            e.printStackTrace();
            }

关于java - 如何从这个 JSONString 解析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20242812/

相关文章:

java - 父类(super class)类型的对象无法访问子类的方法

java - 尝试在 android 中通过 JSONarray 验证密码

json - 如何从 GitHub 克隆所有 repos(包括私有(private) repos)?

python - 如何根据文件中的一个占位符写入字典键和值

json - 这个描述Json语法用什么语言来解释呢?

java - jButtons 在运行时调整大小

java - 安装摄取附件插件错误

java - 创建六角图的问题

android - monodroid .so 文件可以通过 .NET 代码进行管理吗?

android - runnable 中的 handler.postDelayed 在 Kotlin 中显示语法错误 - Android