AppInventor麻烦! (JSON-索引)

问题描述 投票:2回答:1

所以我部分实现的是设置一个从这种形式的天气网站获取JSON文本的应用程序:

    {
"base": "stations",
"clouds": {
    "all": 20
},
"cod": 200,
"coord": {
    "lat": 40.94,
    "lon": 24.41
},
"dt": 1513711200,
"id": 735861,
"main": {
    "humidity": 100,
    "pressure": 1027,
    "temp": 274.15,
    "temp_max": 274.15,
    "temp_min": 274.15
},
"name": "Kavala",
"sys": {
    "country": "GR",
    "id": 5684,
    "message": 0.0039,
    "sunrise": 1513662178,
    "sunset": 1513695412,
    "type": 1
},
"visibility": 10000,
"weather": [
    {
        "description": "few clouds",
        "icon": "02n",
        "id": 801,
        "main": "Clouds"
    }
],
"wind": {
    "deg": 51.0029,
    "speed": 3.07}}

将其解码为一个列表并将结果存储在app中的一些标签盒中。我想从这个JSON中使用的值是:

(“main”:{“temp”:},“weather”:{“main”:},“main”:{“humidity”:},“wind”:{“speed}”。

我使用集成的json解码功能和App Inventor的索引非常有效地完成了这项工作。

区号照片:enter image description here

(屏幕红色指针应该是“天气”:{“main”:}值)

我的问题是,对于一些城市(应用程序从用户输入的城市名称搜索数据),“天气”的索引:{“main”:}和“wind”:{“speed}”是不同的。有没有我可以为这个问题设置检查程序吗?

例如,对于“天气”:{“main”:}在我的代码(图像)中可以看到的通常索引是创建列表的11 2 1 4 2.对于具有不同索引并响应的城市错误我认为它的10 2 1 4 2。

目标:所以我想要做的是找到一种方法来检查11 2 1 4 2上的元素是否存在所以我可以使用它,否则寻找索引10 2 1 4 2使用的元素。

更新:目标完成尽管JSON畸形2依赖查找成对修复了问题!

android json app-inventor
1个回答
1
投票

不要像目前那样使用嵌套的选择列表项块...更好的方法是使用成对块的循环,数据的顺序将不再重要...

How does the lookup in pairs block work? enter image description here

更多链接

© www.soinside.com 2019 - 2024. All rights reserved.