私はjson配列にアクセスしているという点でjson解析を使用して1つの小さなアプリを作成しますが、このjsonarrayでは電話番号のタイトルとアドレスラインが必要ですが、電話番号にアクセスする方法は理解できないので、アクセスする方法
ここにjson形式があります
> {
"responseData": {
"results": [
{
"title": "Pakvan Dining Hall",
"phoneNumbers": [
{
"type": "",
"number": "079 26636473"
},
{
"type": "Mobile",
"number": "09427608429"
}
],
"addressLines": [
"Vadilal Sarabhai Hospital",
"Ahmedabad, Gujarat 380006, India"
]
},
{
"title": " Dining Hall",
"phoneNumbers": [
{
"type": "",
"number": "079 26645473"
},
{
"type": "Mobile",
"number": "09427608429"
},
{
"type": "",
"number": "079 26645473"
},
{
"type": "Mobile",
"number": "09427608429"
}
],
"addressLines": [
" Sarabhai Hospital",
"Ahmedabad, Gujarat 380006, India"
]
},
}
ArrayList> contactList = new ArrayList>();
JsonParser jparser= new JsonParser();
String jsonstringfunction =jparser.jsonstringfunction(url);
Log.e("Jsonstringfunction","n"+jsonstringfunction);
try
{
JSONObject jsonObject2 = new JSONObject(jsonstringfunction);
JSONObject response = jsonObject2.getJSONObject(TAG_RESPONSE);
JSONArray jresults=response.getJSONArray(TAG_RESULTS);
Log.e("check","3333"+jresults);
for (int i = 0; i < jresults.length(); i++)
{
Log.e("check","4444"+jresults.length());
String titlenoformating = jresults.getJSONObject(i).get(TAG_TITLENOFORMATING).toString();
Log.e("Title",""+titlenoformating);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_TITLENOFORMATING,titlenoformating);
JSONArray jaddressline=jresults.getJSONObject(i).getJSONArray(TAG_ADDRESSLINES);
Log.e("addressline","addressline"+jaddressline);
String addressline2="";
for(int j=0;j<jaddressline.length();j++)
{
addressline2=addressline2+jaddressline.getString(j).toString();
Log.e("addressline","jaddressline"+addressline2);
}
// adding each child node to HashMap key => value
map.put(TAG_ADDRESSLINES,addressline2);
JSONArray jphonenumbers=jresults.getJSONObject(i).getJSONArray(TAG_PHONENUMBERS);
for(int k=0;k<jphonenumbers.length();k++)
{
Log.e("Phonenumbers","phonenumbers"+jphonenumbers);
JSONArray jtype=jphonenumbers.getJSONObject(k).getJSONArray(TAG_TYPE);
Log.e("JsonPhone","type"+jtype);
for(int m=0;m<jtype.length();m++)
{
String type=jtype.getString(m).toString();
Log.e("type","type"+type);
}
}
contactList.add(map);
}