我正在尝试阅读以下json回复
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Web.UI;
public partial class CheckboxTest : Page
{
private bool m_PostBackWasEmailChange = false;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
protected override void OnPreRenderComplete(EventArgs e)
{
base.OnPreRenderComplete(e);
ItemPanel.Enabled = true;
}
protected override void OnLoadComplete(EventArgs e)
{
base.OnLoadComplete(e);
if (!IsPostBack)
SendEmail.Checked = true;
else
{
if (m_PostBackWasEmailChange) BoxChange.Text = "Checkbox was turned " + (SendEmail.Checked ? "on" : "off");
}
}
protected override void OnSaveStateComplete(EventArgs e)
{
base.OnSaveStateComplete(e);
}
protected void OnSendEmailChanged(object sender, EventArgs e)
{
m_PostBackWasEmailChange = true;
}
}
我需要一组" apiNames"。下面是关于我如何阅读json的课程
{
"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"
},
}
}
}
运行程序后,我得到了jsonArray" apiGroups"。但在那之后,没有任何反应。有人可以帮我解决这个问题吗?
答案 0 :(得分:1)
试试这个:
JSONObject groupObject = jsonObject.getJSONObject("apiGroups");
String apiName =groupObject.getJSONObject("affiliate").getJSONObject("apiListings").getJSONObject("bags_wallets_belts").getString("apiName");
更具体地说明apiListings下的所有对象:
JSONObject apiListingObject = jsonObject.getJSONObject("apiGroups").getJSONObject("affiliate").getJSONObject("apiListings");
JSONObject obj4=null;
//Getting all the keys inside json object with key- pages
Iterator<String> keys= apiListingObject.keys();
while (keys.hasNext())
{
String keyValue = (String)keys.next();
obj4 = apiListingObject.getJSONObject(keyValue);
//getting string values with keys- apiName
String pageid = obj4.getString("apiName");
}