Я пытаюсь Считайте ответ JSonJsonResponse не работает должным образом
{
"title": "Flipkart Affiliate API Directory",
"description": "This directory contains information about all the affiliate API's and their versions",
"apiGroups": {
"affiliate": {
"name": "affiliate",
"apiListings": {
"bags_wallets_belts": {
"availableVariants": {
"v0.1.0": {
"resourceName": "bags_wallets_belts",
"get": "https://affiliate-api.flipkart.net/affiliate/feeds/youraffiliateid/category/v1:reh.json?expiresAt=1420910131274&sig=7db02590dfaea9a22f88c869d8035d05",
"post": null,
"put": null,
"delete": null
}
},
"apiName": "bags_wallets_belts"
},
"washing_machine": {
"availableVariants": {
"v0.1.0": {
"resourceName": "washing_machine",
"get": "https://affiliate-api.flipkart.net/affiliate/feeds/youraffiliateid/category/v1:j9e-abm-8qx.json?expiresAt=1420910131275&sig=7c48abab9d35ae77fff3d998e1a2efdc",
"post": null,
"put": null,
"delete": null
}
},
"apiName": "washing_machine"
},
}
}
}
мне нужен массив «apiNames». Ниже мой класс о том, как я пытаюсь, чтобы прочитать JSon
class SearchProducts extends AsyncTask<String, Void, Integer> {
final List<RowItem> rowItem = new ArrayList<RowItem>();
final int SUCCESS = 0;
final int FAILURE = SUCCESS + 1;
ProgressDialog dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = ProgressDialog.show(FlipkartProducts.this, "", getString(R.string.searchingflipkart));
}
@Override
protected Integer doInBackground(String... params) {
try {
String urlString = "https://affiliate-api.flipkart.net/affiliate/api/royarnab8.json";
URL url = new URL(urlString);
InputStream inputStream = url.openConnection().getInputStream();
String response = streamToString(inputStream);
JSONObject jsonObject = (JSONObject) new JSONTokener(response).nextValue();
JSONArray jsonArray = jsonObject.getJSONArray("apiGroups");
int a = jsonArray.length();
Log.d("The length of the array is", "" + a);
for (int i =0; i<jsonArray.length(); i++) {
JSONObject mainImageJsonObject = jsonArray.getJSONObject(i).getJSONObject("affiliate")
.getJSONObject("apiListings");
String categories = mainImageJsonObject.getString("apiName");
RowItem ri = new RowItem(categories);
rowItem.add(ri);
}
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
}
return FAILURE;
}
@Override
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
dialog.dismiss();
if (result == SUCCESS) {
lv.setAdapter(new SavedUrlAdapter(FlipkartProducts.this,rowItem));
} else {
Toast.makeText(FlipkartProducts.this, getString(R.string.errorfk), Toast.LENGTH_LONG).show();
}
}
}
public static String streamToString(InputStream p_is)
{
try
{
BufferedReader m_br;
StringBuffer m_outString = new StringBuffer();
m_br = new BufferedReader(new InputStreamReader(p_is));
String m_read = m_br.readLine();
while(m_read != null)
{
m_outString.append(m_read);
m_read =m_br.readLine();
}
return m_outString.toString();
}
catch (Exception p_ex)
{
p_ex.printStackTrace();
return "";
}
}
После запуска программы, я получаю «apiGroups» jsonArray. Но после этого ничего не происходит. Может ли кто-нибудь помочь мне решить эту проблему?
"apiGroups" не является JSONArray – Blackbelt