gpt4 book ai didi

android - AppInventor 麻烦了! (JSON 索引)

转载 作者:行者123 更新时间:2023-11-29 01:05:01 24 4
gpt4 key购买 nike

所以我部分实现的是设置一个从这种形式的天气网站获取 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}}

将它解码成一个列表并将结果存储在应用程序的一些标签框中。我想从这个 JSON 中使用的值是:

("main": {"temp":}, "weather": {"main":}, "main": {"humidity":}, "wind":{"speed}".

我使用集成的 json 解码功能和 App Inventor 的索引非常有效地做到了这一点。

block 代码照片: enter image description here

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

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

For example, for "weather": {"main":} the usual indexing as it can be seen in my code(image) is 11 2 1 4 2 of the created list.For the cities that have different index and respond with an error i think its 10 2 1 4 2.

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

更新:尽管 JSON 畸形 2 依赖成对查找解决了问题,但目标已完成!

最佳答案

不要像您目前所做的那样使用嵌套的选择列表项 block ...更好的方法是使用 loopup in pairs block ,数据的顺序将不再重要......

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

更多链接

关于android - AppInventor 麻烦了! (JSON 索引),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47894500/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com