gpt4 book ai didi

java - 如何从这个 JSONString 解析?

转载 作者:搜寻专家 更新时间:2023-11-01 08:54:13 25 4
gpt4 key购买 nike

我得到以下 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/

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