How can I use API in livecode?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
zhangyouwen
Posts: 11
Joined: Tue Mar 31, 2015 2:14 pm

How can I use API in livecode?

Post by zhangyouwen » Tue Apr 28, 2015 1:38 pm

I am trying to make a weather app, which it will use a weather API that will provide information in json format. But how can I realize it?

For example, the api will provide a link: http://m.weather.com.cn/data/101110101.html (101110101 is the city code, it can be replaced by different code to gather different weather info)

when you go the the link it will appear information like this:

{"weatherinfo":{"city":"西安","city_en":"xian","date_y":"2014年3月4日","date":"","week":"星期二","fchh":"11","cityid":"101110101","temp1":"13℃~3℃","temp2":"8℃~2℃","temp3":"8℃~3℃","temp4":"7℃~1℃","temp5":"13℃~3℃","temp6":"14℃~4℃","tempF1":"55.4℉~37.4℉","tempF2":"46.4℉~35.6℉","tempF3":"46.4℉~37.4℉","tempF4":"44.6℉~33.8℉","tempF5":"55.4℉~37.4℉","tempF6":"57.2℉~39.2℉","weather1":"多云","weather2":"小雨","weather3":"阴转小雨","weather4":"小雨转阴","weather5":"多云","weather6":"多云","img1":"1","img2":"99","img3":"7","img4":"99","img5":"2","img6":"7","img7":"7","img8":"2","img9":"1","img10":"99","img11":"1","img12":"99","img_single":"1","img_title1":"多云","img_title2":"多云","img_title3":"小雨","img_title4":"小雨","img_title5":"阴","img_title6":"小雨","img_title7":"小雨","img_title8":"阴","img_title9":"多云","img_title10":"多云","img_title11":"多云","img_title12":"多云","img_title_single":"多云","wind1":"东风小于3级","wind2":"东风小于3级","wind3":"东风小于3级","wind4":"东风小于3级","wind5":"东风小于3级","wind6":"东风小于3级","fx1":"东风","fx2":"东风","fl1":"小于3级","fl2":"小于3级","fl3":"小于3级","fl4":"小于3级","fl5":"小于3级","fl6":"小于3级","index":"冷","index_d":"天气冷,建议着棉服、羽绒服、皮夹克加羊毛衫等冬季服装。年老体弱者宜着厚棉衣、冬大衣或厚羽绒服。","index48":"较冷","index48_d":"建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。","index_uv":"最弱","index48_uv":"最弱","index_xc":"不宜","index_tr":"适宜","index_co":"较舒适","st1":"13","st2":"3","st3":"6","st4":"2","st5":"9","st6":"3","index_cl":"较适宜","index_ls":"基本适宜","index_ag":"极易发"}}

How can I gather information and put into the corresponding field? And because the weather api provids different code for different cities, how can I realize the function that I can put a city name in a field then click a button, and the app will gather the weather information?

zhangyouwen
Posts: 11
Joined: Tue Mar 31, 2015 2:14 pm

Re: How can I use API in livecode?

Post by zhangyouwen » Tue Apr 28, 2015 1:41 pm

Here are some city codes you could try, although they are in Chinese :D they city name could be in different languages.
101010100=北京
101010200=海淀
101010300=朝阳
101010400=顺义
101010500=怀柔
101010600=通州
101010700=昌平
101010800=延庆
101010900=丰台
101011000=石景山
101011100=大兴
101011200=房山
101011300=密云
101011400=门头沟
101011500=平谷
101011600=八达岭
101011700=佛爷顶
101011800=汤河口
101011900=密云上甸子
101012000=斋堂
101012100=霞云岭

Post Reply