JSON Android解析JSONArray

死者

我正在尝试解析 JSON:

{
    "shopId": 45123,
    "name":"London",
    "desc":"# The city\n## Intro\n**London** is the capital and most populous city of England and the United Kingdom, as well as the most populous municipality in the European Union. Standing on the _River Thames_ in the south east of the island of Great Britain \n## History \n London has been a major settlement for two millennia. It was founded by the Romans, who named it [Londinium](https://en.wikipedia.org/wiki/Londinium). London's ancient core, the City of London, largely retains its 1.12-square-mile (2.9 km2) medieval boundaries.",
    "priceRating": 4.2,
    "qualityRating":5.0,
    "thumbnail":"https://s-media-cache-ak0.pinimg.com/736x/90/63/4e/90634e974743ed9409f527e3b2f24852.jpg",
    "stops": 
    [
        {
            "num": 1,
            "time": "2016-04-27T06:15:00.000Z",
            "title":"Flight to London",
            "desc":"Barcelona BCN-London-Gatwick LGW",
            "type":"0",
            "subtype":0
        },
        {
            "num": 2,
            "time": "2016-04-27T10:35:00.000Z",
            "title":"Gatwick express",
            "desc":"From Airport to London",
            "type":"0",
            "subtype":1
        },
        {
            "num": 3,
            "time": "2016-04-27T12:15:00.000Z",
            "title":"Pub the black horse",
            "desc":"From Airport to London",
            "type":1,
            "subtype":1,
            "location": "51.476334, -0.062700",
            "images": [                 "https://fitzrovianews.files.wordpress.com/2011/01/black_horse_rathbone_pl.jpg" 
            ]               
        },
        {
            "num": 4,
            "time": "2016-04-27T12:16:47.000Z",
            "title":"The Tower Bridge",
            "desc":"# The Tower Bridge Facts\n## Architecture\n**Tower Bridge** is a combined bascule and suspension bridge in London built in _1886–1894_. The bridge crosses the River Thames close to the Tower of London and has become an iconic symbol of London. Tower Bridge is one of five London bridges now owned and maintained by the Bridge House Estates, a charitable trust overseen by the City of London Corporation. \n>It is the only one of the Trust's bridges not to connect the City of London directly to the Southwark bank, as its northern landfall is in Tower Hamlets.\n## The bridge Exhibition\nThis must-see London attraction invites you to step inside the most famous bridge in the world to explore its iconic structure, spectacular views and glass floor, modern exhibitions and magnificent Victorian Engine Rooms! ",
            "type":1,
            "subtype":6,
            "location": "51.507792, -0.087786",
            "images": [                 
    "https://i.ytimg.com/vi/nby0Mr2LfBQ/hqdefault.jpg",
    "http://raindropsofsapphire.com/wp-content/uploads/2011/10/london-bridge.jpg",
    "http://www.londonforfree.net/gizmo/wp-content/uploads/2015/02/southwark-bridge.jpg"
            ]               
        },
        {
            "num": 5,
            "time": "2016-04-27T12:18:10.000Z",
            "title":"St. Paul Cathedral",
            "desc":"# HISTORY \nSt **Paul's Cathedral**, London, is an _Anglican cathedral_, the seat of the _Bishop of London_ and the mother church of the Diocese of London.  \n * It sits on Ludgate Hill at the highest point of the City of London and is a Grade 1 listed building. \n * Its dedication to Paul the Apostle dates back to the original church on this site, founded in AD 604.",
            "type":1,
            "subtype":6,
            "location": "51.513825, -0.098351",
            "images": [                 
    "https://d1wgio6yfhqlw1.cloudfront.net/sysimages/product/resized6/Interior_St_Pauls_Cathedral_132_12992.jpg",
    "https://d1kioxk2jrdjp.cloudfront.net/resized/486x324/48-st_pauls_ctahedral_millenirm_bridge.jpg",
    "http://i4.mirror.co.uk/incoming/article8299330.ece/ALTERNATES/s615b/LOND-2016-052-HMQ-St-Pauls-Thanks-Giving-704JPG.jpg"
            ]               
        }
    ] 
}

当我尝试使用下一个代码解析“图像”元素时,问题就出现了:

for (int i = 0; i < stops.length(); i++) {
            JSONObject c = stops.getJSONObject(i);
.....


if(c.has("images") && !c.isNull("images")){
                JSONArray imagenes = jsonObj.getJSONArray("images");
                for (int j = 0; j < imagenes.length(); j++) {
                     String valueString= imagenes.getString(i);
                    Log.d("myTag", "Viatge Parser  con valuestring" + valueString);
                        URL url2 = new URL(valueString);
                        HttpURLConnection connection = (HttpURLConnection) url2.openConnection();
                        connection.setDoInput(true);
                        connection.connect();
                        InputStream input = connection.getInputStream();
                         Bitmap miBitmap = BitmapFactory.decodeStream(input);
                        s.addImage(miBitmap);
                    }


                }

我已经在检查是否"images"存在,但我不断收到此错误:

03-22 00:23:51.391 23180-23797/com.example.usuari.myapplication3 I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
03-22 00:23:51.391 23180-23797/com.example.usuari.myapplication3 I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
03-22 00:23:51.801 23180-23797/com.example.usuari.myapplication3 W/System.err: org.json.JSONException: No value for images
03-22 00:23:51.801 23180-23797/com.example.usuari.myapplication3 W/System.err:     at org.json.JSONObject.get(JSONObject.java:389)
03-22 00:23:51.801 23180-23797/com.example.usuari.myapplication3 W/System.err:     at org.json.JSONObject.getJSONArray(JSONObject.java:584)
03-22 00:23:51.801 23180-23797/com.example.usuari.myapplication3 W/System.err:     at com.example.usuari.myapplication3.ViatgeParser.parseFromJSON(ViatgeParser.java:97)
03-22 00:23:51.801 23180-23797/com.example.usuari.myapplication3 W/System.err:     at com.example.usuari.myapplication3.DownloadAsyncTask.doInBackground(DownloadAsyncTask.java:38)
03-22 00:23:51.801 23180-23797/com.example.usuari.myapplication3 W/System.err:     at com.example.usuari.myapplication3.DownloadAsyncTask.doInBackground(DownloadAsyncTask.java:17)
03-22 00:23:51.801 23180-23797/com.example.usuari.myapplication3 W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:295)
03-22 00:23:51.801 23180-23797/com.example.usuari.myapplication3 W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-22 00:23:51.801 23180-23797/com.example.usuari.myapplication3 W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
03-22 00:23:51.801 23180-23797/com.example.usuari.myapplication3 W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
03-22 00:23:51.801 23180-23797/com.example.usuari.myapplication3 W/System.err:     at java.lang.Thread.run(Thread.java:818)

如果我已经在if语句中进行了适当的检查,我不明白我怎么会收到这个错误

格斯

改成JSONArray imagenes = jsonObj.getJSONArray("images");
这个JSONArray imagenes = c.getJSONArray("images");

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

android json解析错误-无法将JSONArray转换为JSONObject

来自分类Dev

Android JSON解析“无法将org.json.JSONObject类型的数据转换为JSONArray”错误

来自分类Dev

当JSONArray之前没有节点时,如何解析Json数据?(Android)

来自分类Dev

我无法解析为什么在我的android项目中解析JSON(如“ JSONObject无法转换为JSONArray”)时显示异常

来自分类Dev

在Android中解析JSON响应“无法将org.json.JSONObject类型的响应转换为JSONArray”

来自分类Dev

我还是JSON和android的新手,没有得到如何解析内部“选项” JSONArray的信息

来自分类Dev

用于JSON解析的Android模型显示ClassCastException:com.google.gson.JsonObject无法转换为com.google.gson.JsonArray

来自分类Dev

Android:JSONArray解析问题

来自分类Dev

Android:解析2 jsonArray

来自分类Dev

Android解析2 jsonarray

来自分类Dev

Json解析gorg.json.JSONObject无法转换为JSONArray

来自分类Dev

Android Jsonarray无法转换为json对象

来自分类Dev

如何使用GSON WHen对象解析JSON是JSONObject还是JSONArray

来自分类Dev

如何使用Json.simple解析Java中的JSONArray?

来自分类Dev

使用gson解析jsonarray中的多个json对象

来自分类Dev

如何使用GSON WHen对象解析JSON是JSONObject还是JSONArray

来自分类Dev

使用Javas JSONArray解析JSON数据时出错

来自分类Dev

解析 JSON - JSONObject 类型的 null 无法转换为 JSONArray

来自分类Dev

Android解析JSON数组

来自分类Dev

Android JSON解析错误

来自分类Dev

Android解析HAL + JSON

来自分类Dev

Android JSON解析

来自分类Dev

Android解析JSON

来自分类Dev

Android和JSON解析

来自分类Dev

Android:从网址解析JSON

来自分类Dev

(Android)Java:JSON解析

来自分类Dev

Android Json解析建议

来自分类Dev

Android JSON多对解析

来自分类Dev

Android App JSON解析

Related 相关文章

  1. 1

    android json解析错误-无法将JSONArray转换为JSONObject

  2. 2

    Android JSON解析“无法将org.json.JSONObject类型的数据转换为JSONArray”错误

  3. 3

    当JSONArray之前没有节点时,如何解析Json数据?(Android)

  4. 4

    我无法解析为什么在我的android项目中解析JSON(如“ JSONObject无法转换为JSONArray”)时显示异常

  5. 5

    在Android中解析JSON响应“无法将org.json.JSONObject类型的响应转换为JSONArray”

  6. 6

    我还是JSON和android的新手,没有得到如何解析内部“选项” JSONArray的信息

  7. 7

    用于JSON解析的Android模型显示ClassCastException:com.google.gson.JsonObject无法转换为com.google.gson.JsonArray

  8. 8

    Android:JSONArray解析问题

  9. 9

    Android:解析2 jsonArray

  10. 10

    Android解析2 jsonarray

  11. 11

    Json解析gorg.json.JSONObject无法转换为JSONArray

  12. 12

    Android Jsonarray无法转换为json对象

  13. 13

    如何使用GSON WHen对象解析JSON是JSONObject还是JSONArray

  14. 14

    如何使用Json.simple解析Java中的JSONArray?

  15. 15

    使用gson解析jsonarray中的多个json对象

  16. 16

    如何使用GSON WHen对象解析JSON是JSONObject还是JSONArray

  17. 17

    使用Javas JSONArray解析JSON数据时出错

  18. 18

    解析 JSON - JSONObject 类型的 null 无法转换为 JSONArray

  19. 19

    Android解析JSON数组

  20. 20

    Android JSON解析错误

  21. 21

    Android解析HAL + JSON

  22. 22

    Android JSON解析

  23. 23

    Android解析JSON

  24. 24

    Android和JSON解析

  25. 25

    Android:从网址解析JSON

  26. 26

    (Android)Java:JSON解析

  27. 27

    Android Json解析建议

  28. 28

    Android JSON多对解析

  29. 29

    Android App JSON解析

热门标签

归档