javascript
json在android的应用,JSON解析在android应用程序
你JSON無效。確保始終在Validating JSON中檢查您的JSON。這是如何將其拆分為具有修改的JSON的類別:
String jsonString = "[\n" +
" {\n" +
" \"Men\": \"\",\n" +
" \"shirts\": [\n" +
" {\n" +
" \"name\": \"ABC\",\n" +
" \"image\": \"http://domain.com/image.jpg\"\n" +
" },\n" +
" {\n" +
" \"name\": \"USA\",\n" +
" \"image\": \"imageURLg\"\n" +
" }\n" +
" ],\n" +
" \"Pants\": [\n" +
" {\n" +
" \"name\": \"sample\",\n" +
" \"image\": \"imageurl\"\n" +
" },\n" +
" {\n" +
" \"name\": \"shoper\",\n" +
" \"image\": \"imageurl\"\n" +
" }\n" +
" ]\n" +
" }\n" +
"]";
try{
JSONArray array = new JSONArray(jsonString);
//Get the shirts
JSONArray shirtsArray = array.getJSONObject(0).getJSONArray("shirts");
Log.d(LOG_TAG,"shirtsArray = " + shirtsArray.toString());
for (int i = 0; i < shirtsArray.length(); i++){
Log.d(LOG_TAG, "name = " + shirtsArray.getJSONObject(i).getString("name")+" image: "+shirtsArray.getJSONObject(i).getString("image"));
}
//Get the pants
JSONArray pantsArray = array.getJSONObject(0).getJSONArray("Pants");
Log.d(LOG_TAG,"shirtsArray = " + shirtsArray.toString());
for (int i = 0; i < pantsArray.length(); i++){
Log.d(LOG_TAG, "name = " + pantsArray.getJSONObject(i).getString("name")+" image: "+pantsArray.getJSONObject(i).getString("image"));
}
}catch (JSONException ex){
Log.e(LOG_TAG, ex.toString());
}
總結
以上是生活随笔為你收集整理的json在android的应用,JSON解析在android应用程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Zend Studio使用教程之升级Ze
- 下一篇: js设置全局变量ajax中赋值