我得到了一些來自服務器端的響應,我需要解析但不是通過名稱,即響應會隨時變化。android:json異常
type = "data_updates";
updates = {
"offers_all" = {
columns = (
"record_id",
"display_name",
"sorting_name",
latitude,
longitude,
"custom_ad_banner_resource_id",
description,
"website_url",
"phone_number",
hours,
advertiser,
"street_address",
"offer_id",
"offer_section",
"start_date",
"end_date",
"custom_leaf_template",
"location_area"
);
data = (
(
"09834-234234",
"The Example Offer",
"example offer, the",
"-122.234234",
"31.2342343",
"",
"An Example of an Offer.",
"http=>//freeruntech.com/",
"1.707.555.1212",
"10am - 5pm",
Yes,
"3145 State Street,\nCalistoga, CA, 94500",
"",
"",
"2011-08-24",
"2011-12-31",
"",
Napa
)}
我用下面的代碼獲取主一個JSONObjects
if (show.get("type").equals("data_updates"))
{
JSONObject data_updates = show.getJSONObject("updates");
JSONArray array_containing_values= new JSONArray();
JSONArray data_updates_values=data_updates.names();
System.out.println(data_updates_values);
for(int m=0; m<data_updates_values.length(); m++)
{
JSONObject obj = new JSONObject((String) data_updates_values.get(m));
JSONArray names = new JSONArray();
names= obj.toJSONArray(names);
System.out.println(names);
}
}
但它給我的異常
Value events of type java.lang.String cannot be converted to JSONObject
我應如何獲得數據和列JSonobjects
的值。
任何人都可以幫助我嗎?
謝謝
它看起來不是有效的JSON。你確定你得到了JSON嗎? –
雅我相信它只是json – Aditya1510
@Nikita其實我在這裏寫了一部分,其實反應非常大。 – Aditya1510