Unable to decode the JSON text

http://ai2.appinventor.mit.edu/reference/blocks/dictionaries.html#list-by-walking-key-path

2 Likes

The issue could of course be that the JSON data is incorrectly formed/has bad syntax. Error 1105 means "Unable to decode the JSON text", which may well indicate that there is something wrong with it.

1 Like

Developers can use this online json validator to determine if they are using a 'properly' formatted json

3 Likes

With extension:

https://community.appinventor.mit.edu/t/extension-json-decode-jsonpath-get-the-value-easily-convert-xml-json/43931

borr_jsondecode.aia (582.8 KB)

2 Likes



By the way,what the arguments mean?


Did It show the JSON was legal?




\Using list to analizy the JSON will cause this problem?

Try when when web got text instead of when got file

image

3 Likes

Also, replace fileName with responseContent after you change the event.

3 Likes

I have tried it.It seems that the API response a file not a text.


标签2 showed "nooo".

So I think the next problem is taht how to read JSON from the file.

Response:
200
Date: Tue, 03 May 2022 11:02:05 GMT
Content-Type: application/json;charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=25
Vary: Accept-Encoding
Access-Control-Allow-Headers: *
showapi_fee_num: 1
X-Ca-Request-Id: 3C9BCFB8-DC9B-4A74-BCB7-C3E88D543B83
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Max-Age: 1728000

{
"showapi_res_error": "",
"showapi_res_id": "62710bad0de3769e0691dcb6",
"showapi_res_code": 0,
"showapi_fee_num": 1,
"showapi_res_body": {"ret_code":0,"cityInfo":{"c6":"hunan","c5":"湘潭","c4":"xiangtan","c3":"湘潭","c9":"中国","c8":"china","c7":"湖南","c17":"+8","c16":"AZ9731","c1":"101250201","c2":"xiangtan","c0":"430300","c11":"0731","longitude":112.908,"latitude":27.867,"c10":"2","c12":"411100","c15":"64"},"f1":{"night_weather_code":"01","day_weather":"雾","night_weather":"多云","jiangshui":"31%","air_press":"1010.9hPa","night_wind_power":"0-3级 <5.4m/s","day_wind_power":"0-3级 <5.4m/s","day_weather_code":"18","sun_begin_end":"05:47|19:03","ziwaixian":"中等","day_weather_pic":"http://app1.showapi.com/weather/icon/day/18.png","weekday":2,"night_air_temperature":"16","day_air_temperature":"28","day_wind_direction":"北风","day":"20220503","night_weather_pic":"http://app1.showapi.com/weather/icon/night/01.png","night_wind_direction":"东南风"},"f2":{"night_weather_code":"00","day_weather":"多云","night_weather":"晴","jiangshui":"7%","air_press":"1009.7hPa","night_wind_power":"0-3级 <5.4m/s","day_wind_power":"0-3级 <5.4m/s","day_weather_code":"01","sun_begin_end":"05:46|19:03","ziwaixian":"中等","day_weather_pic":"http://app1.showapi.com/weather/icon/day/01.png","weekday":3,"night_air_temperature":"15","day_air_temperature":"28","day_wind_direction":"西南风","day":"20220504","night_weather_pic":"http://app1.showapi.com/weather/icon/night/00.png","night_wind_direction":"东南风"},"f3":{"night_weather_code":"01","day_weather":"多云","night_weather":"多云","jiangshui":"4%","air_press":"1006.3hPa","night_wind_power":"0-3级 <5.4m/s","day_wind_power":"0-3级 <5.4m/s","day_weather_code":"01","sun_begin_end":"05:45|19:04","ziwaixian":"中等","day_weather_pic":"http://app1.showapi.com/weather/icon/day/01.png","weekday":4,"night_air_temperature":"16","day_air_temperature":"30","day_wind_direction":"南风","day":"20220505","night_weather_pic":"http://app1.showapi.com/weather/icon/night/01.png","night_wind_direction":"东南风"},"now":{"aqiDetail":{"co":"0.5","num":"237","area":"湘潭","so2":"11","o3":"164","no2":"12","quality":"良好","aqi":"55","pm10":"36","pm2_5":"21","o3_8h":"161","primary_pollutant":"O3"},"weather_code":"00","temperature_time":"19:00","wind_direction":"西风","wind_power":"1级","sd":"43%","aqi":"55","weather":"晴","weather_pic":"http://app1.showapi.com/weather/icon/day/00.png","rain":"0.0","temperature":"25"},"time":"20220503180000"}
}

You are not getting a file, you are getting text content (json)

Can you please share the url you use to get json ?


Url: http://weather01.market.alicloudapi.com/area-to-weather?area=丽江&areaCode=530700&areaid=101291401&needMoreDay=0&needAlarm=0&need3HourForcast=0&needIndex=0&needHourData=0

I bought the API from aliyun.Aliyun is a online market and belong to Alibaba(易源数据-全国天气预报查询【最新版】-云市场-阿里云)

Try this

weather_api.aia (2.6 KB)

1 Like

I'll try tomorrow. Thank you.

Respect!!!
These blocks can satisfy the needs.
But it can't work successfuly on Chinese user's APP inventor 1.Becsuse it don't have the function of DICTIONARY.Chinese user can use APP Inventor in two ways.
First MIT App Inventor (gzjkw.net)
This is free.But it don't have the function of DICTIONARY.That why I didn't use dictionay at first.

Second WxBit 图形化编程 - 登录(https://app.wxbit.com/login/)
You have to pay for this.9.9 Yuan per month.And it has a minor change .
weather_api.aia (2.7 KB)

WxBit should have their own forum (they are a clone of App Inventor, and they have differences with App Inventor). So please ask in their own forum. However, if you want it to be free, you should also be able to access the other App Inventor server at http://code.appinventor.mit.edu/ in mainland China.

Also instead of using dictionary blocks use extension provided by @Juan_Antonio Unable to decode the JSON text - #20 by Juan_Antonio

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.