2015-03-31 2 views
-1

Я сделал кодирование с использованием фрагмента.Как получить значения внутренних объектов внутри json-массива

это мой homeFragment

res = out.toString(); 
         JSONArray arrJsonArray=new JSONArray(res); 
         for (int i = 0; i < arrJsonArray.length(); i++) { 
          JSONObject object = arrJsonArray.getJSONObject(i); 
          Data data=new Data(); 
          data.setName(object.getString("title")); 
          data.setMsg(object.getString("slug")); 
          /* for abouve code i am getting data for below code i am not able to retrive the data*/ 
          object.getJSONObject("offer_shop_details"); 
          data.setOffer(object.getString("time_field_from_sunday")); 
          itemList.add(data); 
         } 

ниже моего JSON. Я jsonArray

Я дал один элемент массива моего json.

Мне нужно получить данные внутри «offer_shop_details», и выше это моя логика. помогите мне найти правильный ответ.

json ниже, если вы подтвердите его, сообщите недействительным. потому что я дал только его часть.

  [ 
{ 
ID: 528, 
title: "Buy breakfast meal get free salad", 
status: "publish", 
type: "offers", 
content: "", 
parent: 0, 
link: "", 
date: "2015-03-30T10:25:29+00:00", 
slug: "buy-breakfast-meal-get-free-salad-2", 
excerpt: null, 
meta: { 
links: { 
self: "", 
author: "", 
collection: "", 
replies: "", 
version-history: "" 
} 
}, 
offer_shop_details: { 
time_field_from: "03:00", 
time_field_to: "18:45", 
time_field_from_sunday: "10:00", 
time_field_to_sunday: "00:00", 
time_field_from_monday: "10:00", 
time_field_to_monday: "00:00", 
time_field_from_tuesday: "10:00", 
time_field_to_tuesday: "00:00", 
time_field_from_wednesday: "10:00", 
time_field_to_wednesday: "00:00", 
time_field_from_thursday: "10:00", 
time_field_to_thursday: "00:00", 
time_field_from_friday: "10:00", 
time_field_to_friday: "00:00", 
time_field_from_saturday: "10:00", 
time_field_to_saturday: "00:00", 
afflshop_address: "Manama", 
afflshop_website: "", 
afflshop_image_id: { 
id: "278", 
url: "" 
} 
}, 
mall_shop_details: false, 
author: { 
ID: 1, 
username: "bm", 
name: "bm", 
first_name: "", 
last_name: "", 
nickname: "bm", 
slug: "bm", 
URL: "", 
avatar: "", 
description: "", 
registered: "2015-01-11T07:25:06+00:00", 
meta: { 
links: { 
self: "", 
archives: "" 
} 
} 
}, 
featured_image: null, 
terms: { 
offershop: [ 
{ 
ID: 29, 
name: "Salad boutique", 
slug: "salad-boutique", 
description: "", 
parent: { 
ID: 31, 
name: "Restaurant", 
slug: "restaurant", 
description: "", 
parent: null, 
count: 0, 
link: "", 
meta: { 
links: { 
collection: "", 
self: "" 
} 
} 
}, 
count: 1, 
link: "", 
meta: { 
links: { 
collection: "", 
self: "" 
} 
} 
} 
] 
} 
}, 
{ 
ID: 527, 
title: "One Full Service Second for Half Price", 
status: "publish", 
type: "offers", 
content: "", 
parent: 0, 
link: "", 
date: "2015-03-30T10:21:17+00:00", 
slug: "one-full-service-second-for-half-price-2", 
excerpt: null, 
meta: { 
links: { 
self: "", 
author: "", 
collection: "", 
replies: "", 
version-history: "" 
} 
}, 
offer_shop_details: { 
time_field_from_sunday: "10:00", 
time_field_to_sunday: "22:00", 
time_field_from_monday: "10:00", 
time_field_to_monday: "22:00", 
time_field_from_tuesday: "10:00", 
time_field_to_tuesday: "22:00", 
time_field_from_wednesday: "10:00", 
time_field_to_wednesday: " 22:00", 
time_field_from_thursday: "10:00", 
time_field_to_thursday: "22:00", 
time_field_from_friday: "10:00", 
time_field_to_friday: "22:00", 
time_field_from_saturday: "10:00", 
time_field_to_saturday: "22:00", 
afflshop_address: "Name: Aya EL Baba Email: [email protected] Address: SEEF Location: Adliya", 
afflshop_website: "", 
afflshop_contact: "+. 973 36 9999 25", 
afflshop_image_id: { 
id: "279", 
url: "" 
} 
}, 
mall_shop_details: false, 
author: { 
ID: 1, 
username: "bm", 
name: "bm", 
first_name: "", 
last_name: "", 
nickname: "bm", 
slug: "bm", 
URL: "", 
avatar: "", 
description: "", 
registered: "2015-01-11T07:25:06+00:00", 
meta: { 
links: { 
self: "", 
archives: "" 
} 
} 
}, 
featured_image: null, 
terms: { 
offershop: [ 
{ 
ID: 36, 
name: "TONY &amp; GUY", 
slug: "tony-and-guy", 
description: "TONI&amp;GUY is the most powerful hairdressing brand in the world. The company is constantly evolving artistically and commercially. It offers the best education on the planet and boasts fabulous product ranges and a dynamic and modern image.", 
parent: { 
ID: 35, 
name: "Saloon", 
slug: "saloon", 
description: "", 
parent: null, 
count: 0, 
link: "", 
meta: { 
links: { 
collection: "", 
self: "" 
} 
} 
}, 
count: 1, 
link: "", 
meta: { 
links: { 
collection: "", 
self: "" 
} 
} 
} 
] 
} 
}, 
{ 
ID: 482, 
title: "Sample Offer", 
status: "publish", 
type: "offers", 
content: "", 
parent: 0, 
link: "", 
date: "2015-03-26T10:48:35+00:00", 
slug: "sample-offer-10", 
excerpt: null, 
meta: { 
links: { 
self: "", 
author: "", 
collection: "", 
replies: "", 
version-history: "" 
} 
}, 
offer_shop_details: { 
afflshop_days: [ 
"0", 
"1", 
"2", 
"3", 
"4", 
"5", 
"6" 
], 
time_field_from: "09:00", 
time_field_to: "22:00", 
afflshop_address: "New extention Seef Mall, 1st Floor, Manama, Bahrain", 
afflshop_website: "", 
afflshop_email: "[email protected]", 
afflshop_contact: "3333286", 
afflshop_image_id: { 
id: "512", 
url: "" 
} 
}, 
mall_shop_details: false, 
author: { 
ID: 1, 
username: "bm", 
name: "bm", 
first_name: "", 
last_name: "", 
nickname: "bm", 
slug: "bm", 
URL: "", 
avatar: "", 
description: "", 
registered: "2015-01-11T07:25:06+00:00", 
meta: { 
links: { 
self: "", 
archives: "" 
} 
} 
}, 
featured_image: null, 
terms: { 
offershop: [ 
{ 
ID: 62, 
name: "Organic Foods and Café", 
slug: "organic-foods-and-cafe", 
description: "", 
parent: { 
ID: 31, 
name: "Restaurant", 
slug: "restaurant", 
description: "", 
parent: null, 
count: 0, 
link: "", 
meta: { 
links: { 
collection: "", 
self: "" 
} 
} 
}, 
count: 1, 
link: "", 
meta: { 
links: { 
collection: "", 
self: "" 
} 
} 
} 
] 
} 
} 
] 

ответ

0

Корень вашей JSON строки является JSONObject так что используйте его, чтобы разобрать ваш JSON, а затем использовать getJSONArray, чтобы получить массив JSON:

res = out.toString(); 

JSONObject rootJsonObject = new JSONObject(res); 

// And then you can access to your array 
JSONArray arrJsonArray= jsonObject.getJSONArray(rootJsonObject); 
+0

мой корень JSONArray не JSONObject. Я только что поставил массив 0, выше. мой json начинается с [скобки и сразу с {this. Я не могу поставить полную ссылку. –

Смежные вопросы