2016-07-25 2 views
0

он показывает мне следующее сообщение об ошибке:JSONObject не может быть преобразован в JSONArray, когда возвращение массив

JSONObject не может быть преобразован в JSONArray

Вот мой код:

JSONArray jsonArray = jsonObject.getJSONArray("GetTabDataResult"); 

Моего JSON Результат:

{"GetTabDataResult":{"TabId":1,"Bands":[{"Id":1,"ImageURL":"http:\/\/www.yallaasouq.com\/bands\/1.jpg","BrandId":0,"Men":true,"Women":true,"Kids":true,"Accessories":true,"Disabled":false,"Title":"","Type":0,"TypeId":0},{"Id":2,"ImageURL":"http:\/\/www.yallaasouq.com\/bands\/2.jpg","BrandId":0,"Men":true,"Women":true,"Kids":true,"Accessories":true,"Disabled":false,"Title":"","Type":0,"TypeId":0},{"Id":3,"ImageURL":"http:\/\/www.yallaasouq.com\/bands\/3.jpg","BrandId":0,"Men":true,"Women":true,"Kids":true,"Accessories":true,"Disabled":false,"Title":"","Type":0,"TypeId":0},{"Id":4,"ImageURL":"http:\/\/www.yallaasouq.com\/bands\/4.jpg","BrandId":0,"Men":true,"Women":true,"Kids":true,"Accessories":true,"Disabled":false,"Title":"","Type":0,"TypeId":0}],"Brands":[{"Id":4,"ArName":"Fabillo","EnName":"Fabillo","Code":"","Description":"","ImageURL":"http:\/\/www.yallaasouq.com\/brands\/fabillo.jpg","Men":true,"Women":false,"Kids":false,"Accessories":false,"FacebookLink":"","InstagrmLink":"","Disabled":false},{"Id":7,"ArName":"Carolina Boix","EnName":"Carolina Boix","Code":"","Description":"","ImageURL":"http:\/\/www.yallaasouq.com\/brands\/eva.jpg","Men":true,"Women":true,"Kids":false,"Accessories":false,"FacebookLink":"","InstagrmLink":"","Disabled":false},{"Id":9,"ArName":"Sport Master","EnName":"Sport Master","Code":"","Description":"","ImageURL":"http:\/\/www.yallaasouq.com\/brands\/sportmaster.jpg","Men":true,"Women":true,"Kids":true,"Accessories":false,"FacebookLink":"","InstagrmLink":"","Disabled":false},{"Id":10,"ArName":"Bershka","EnName":"Bershka","Code":"","Description":"","ImageURL":"http:\/\/www.yallaasouq.com\/brands\/eva.jpg","Men":true,"Women":true,"Kids":true,"Accessories":true,"FacebookLink":"","InstagrmLink":"","Disabled":false},{"Id":11,"ArName":"NO EXCESS","EnName":"NO EXCESS","Code":"","Description":"","ImageURL":"http:\/\/www.yallaasouq.com\/brands\/noexcess.jpg","Men":true,"Women":true,"Kids":true,"Accessories":true,"FacebookLink":"","InstagrmLink":"","Disabled":false}],"Categories":[{"Id":8,"EnName":"T-Shirts","ArName":"بلوزات","Code":"8","Men":true,"Women":true,"Kids":true,"Accessories":false,"MenImgURL":"http:\/\/www.yallaasouq.com\/Categories\/tshirt01.jpg","WomenImgURL":"","KidsImgURL":"","AccessoriesImgURL":""},{"Id":14,"EnName":"Shoes","ArName":"احذية","Code":"14","Men":true,"Women":true,"Kids":true,"Accessories":false,"MenImgURL":"http:\/\/www.yallaasouq.com\/Categories\/shoes01.jpg","WomenImgURL":"","KidsImgURL":"","AccessoriesImgURL":""},{"Id":17,"EnName":"Accessories","ArName":"اكسسوارت","Code":"17","Men":true,"Women":true,"Kids":false,"Accessories":false,"MenImgURL":"http:\/\/www.yallaasouq.com\/Categories\/accessories01.jpg","WomenImgURL":"","KidsImgURL":"","AccessoriesImgURL":""},{"Id":6833,"EnName":"Pants","ArName":"بنطلونات","Code":"6833","Men":true,"Women":true,"Kids":true,"Accessories":false,"MenImgURL":"http:\/\/www.yallaasouq.com\/Categories\/pants01.jpg","WomenImgURL":"","KidsImgURL":"","AccessoriesImgURL":""},{"Id":6834,"EnName":"Shirts","ArName":"قمصان","Code":"6834","Men":true,"Women":true,"Kids":true,"Accessories":false,"MenImgURL":"http:\/\/www.yallaasouq.com\/Categories\/hoodie01.jpg","WomenImgURL":"","KidsImgURL":"","AccessoriesImgURL":""}]}} 

Я знаю, что у моего json есть объекты sub json (Bands, Br ands, Categories), но в основном объекте (GetTabDataResult) есть (TabId), который является значением, а не суб-объектом.

I also checked the service result in the fiddler and i attached here a photo of the screen...you can check it.

+4

'GetTabDataResult' - это jsonobject, а не jsonArray –

ответ

2

использование

JSONObject jsonOb = jsonObject.getJSONObject("GetTabDataResult"); 

вместо

JSONArray jsonArray = jsonObject.getJSONArray("GetTabDataResult"); 

это jsonarray

Bands, Brands, Categories

JsonArray bands =jsonOb.getJsonArray("Bands"); 

Надеюсь, что код полезен для вас!

1

Я не вижу JsonArray в Json String, который вы указали, что это единственный объект JSON. Json Arrays обрабатываются [ ].

Так вместо того, чтобы преобразовать его в обычный JSONObject:

jsonObject.getJSONObject("GetTabDataResult"); 
Смежные вопросы