我正在发送一个json数组,该数组使用android中的StringEntity类转换为String。我在php中收到一个类似下面的字符串。
{
"introduceesJson": [
{
"infoName": "Aa",
"direction": "2",
"version": "1",
"infoNumber": "96 35 874125"
},
[
{
"infoName": "Aa",
"direction": "2",
"version": "1",
"infoNumber": "96 35 874125"
}
]
]
}
现在,我想把它转换成json数组并循环使用。伙计们,请帮帮我。任何帮助都将不胜感激。
try {
JSONArray arr = new JSONArray("Your_String");
for (int i=0;i<arr.length();i++) {
JSONObject object = arr.getJSONObject(i);
String data = object.getString("Your_key");
}
} catch (JSONException e) {
e.printStackTrace();
}
试试这个。
$a=' {
"introduceesJson": [
{
"infoName": "Aa",
"direction": "2",
"version": "1",
"infoNumber": "96 35 874125"
},
[
{
"infoName": "Aa",
"direction": "2",
"version": "1",
"infoNumber": "96 35 874125"
}
]
]
}';
$res=json_decode($a,true);
$data=array();
$data=$res['introduceesJson'];
echo sizeof($data);