Aşağıda benim ben (kod Log.i ("callinfo", callInfo + "") okumaya çalışıyorum json vardır;. Itibaren, ama hata alıyorum Kodum da bahsedilmektedir okumak ve hata mesajı içinjson okuma hatası nasıl giderilir?
{
"CallInfo":[
{
"ItemInfo":[
{
"chargeable":"True",
"itemID":"B13984350K"
},
{
"chargeable":"True",
"itemID":"B13984351A"
}
],
"numberOfCopies":2
}
],
"ISBN":[
""
],
"TitleAvailabilityInfo":null,
"author":"Chief Army Medical Officer.",
"baseCallNumber":"RC87.1 PRE",
"publisherName":"HQ Army Medical Services,",
"title":"Preventing heat injuries : the commanders' guide",
"titleID":9206,
"yearOfPublication":"2000"
}
.
Kod:.
İştemArray2 = callInfo.getJSONArray("ItemInfo");
Error:
org.json.JSONException: No value for ItemInfo
03-28 16:33:09.953 17229-17229/com.androidatc.customviewindrawer W/System.err: at org.json.JSONObject.get(JSONObject.java:389)
03-28 16:33:09.953 17229-17229/com.androidatc.customviewindrawer W/System.err: at org.json.JSONObject.getJSONArray(JSONObject.java:584)
biz ItemInfo değer var açıkça görebilirsiniz
: aşağıdaki satırdapublic void readBarCode(String response, String scannedBarcode) {
final CountDownLatch latch = new CountDownLatch(1);
final String[] names = new String[4];
JSONArray mArray, mArray1, mArray2;
int totalCount = 0;
int avail = 0;
String author, title, publisherName;
try {
JSONObject obj = new JSONObject(response);
//Results
if (obj.getJSONObject("Results") != null) {
JSONObject obj1 = obj.getJSONObject("Results");
//LookupTitleInfoResponse
if (obj1.getJSONObject("LookupTitleInfoResponse") != null) {
JSONObject obj2 = obj1.getJSONObject("LookupTitleInfoResponse");
//TitleInfo
if (obj2.getJSONArray("TitleInfo") != null) {
mArray = obj2.getJSONArray("TitleInfo");
JSONObject callInfo = mArray.getJSONObject(0);
Log.i("callinfo", callInfo + "");
mArray2 = callInfo.getJSONArray("ItemInfo");
for (int i = 0; i <= mArray2.length(); i++) {
if (mArray2.getJSONObject(i).getString("chargeable").equals("False")) {
totalCount++;
}
if (mArray2.getJSONObject(i).getString("itemID").equals(scannedBarcode)) {
avail = 1;
}
}
author = mArray.getJSONObject(0).getString("author");
publisherName = mArray.getJSONObject(0).getString("publisherName");
title = mArray.getJSONObject(0).getString("title");
TitleTxt.setText(title);
PublisherTxt.setText(publisherName);
CreatorTxt.setText(author);
BookBarcode.setText(scannedBarcode);
AvailabiltyTxt.setText(totalCount);
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
hata alınıyor
Herkes bana söyleyebilir mi - yukarıdaki hatayı nasıl giderebilirim? Çok teşekkürler şimdiden.
İştemArray = obj2.getJSONArray("TitleInfo"); JSONObject titleInfo = mArray.getJSONObject(0); JSONArray arr1 = titleInfo.getJSONArray("CallInfo"); JSONObject callInfo = arr1.getJSONObject(0); JSONArray arr2 = callInfo.getJSONArray("ItemInfo"); Log.i("ItemInfo", arr2 + "");
tam yöntemini public void readBarCode (String tepkisi, dize scannedBarcode) {olduğu kodunun altına olan
Olası kopyalar [Android'de JSON verilerini ayrıştırmak nasıl ] (http://stackoverflow.com/questions/8178681/how-to-parse-json-data-in-android) –
Bize geçerli bir JSON gösterebilir misiniz? JSON’unuz geçerli bir JSON olarak ayrıştırılamaz. –
Lütfen orijinal json verilerinizi koyun. –