Arrays 如何在livecode中解析Json?

Arrays 如何在livecode中解析Json?,arrays,json,livecode,Arrays,Json,Livecode,我正在尝试使用由提供的API制作一个天气应用程序 我的堆栈上有三个元素:weatherdata字段、cityfield和一个按钮。其思想是在桌面上保存一个cities.txt文件,其中存储了城市名称及其与API相同的对应代码。大概是这样的: 101010100=Beijing 101010300=Chaoyang 101010400=Shuangyi 101010500=Huairou 101010600=Tongzhou 101010700=Changping 101010800=Yanqin

我正在尝试使用由提供的API制作一个天气应用程序

我的堆栈上有三个元素:weatherdata字段、cityfield和一个按钮。其思想是在桌面上保存一个cities.txt文件,其中存储了城市名称及其与API相同的对应代码。大概是这样的:

101010100=Beijing
101010300=Chaoyang
101010400=Shuangyi
101010500=Huairou
101010600=Tongzhou
101010700=Changping
101010800=Yanqing
on mouseUp
  put the text of fld "city" into tCityName
  put specialFolderPath("desktop") & "/cities.txt" into tFilePath
  put textDecode(tCityList,"UTF8") into tCityList 
  put lineOffset("=" & tCityName & cr,tCityList & cr) into tFoundLine
  set the itemDelimiter to "="
  put item 1 of line tFoundLine of tCityList into tCityCode
  put "http://m.weather.com.cn/data/" & tCityCode & ".html" into tURL
  put URL tURL into tRawJSON
  put textDecode(tRawJSON,"UTF8") into fld "weatherdata"
end mouseUp
API是一个链接: http://m.weather.com.cn/data/city code.html例如,如果我想要北京的天气信息,链接如下:

当进入链接时,它将以JSON格式提供天气数据,如:

{"weatherinfo":{"city":"西安","city_en":"xian","date_y":"2014年3月4日","date":"","week":"星期二","fchh":"11","cityid":"101110101","temp1":"13℃~3℃"...}
我想让我的应用程序从中收集信息,只在相应字段中显示特定信息

基本上,我想要的是当我在city字段中键入Beijing并单击按钮时,应用程序将把city code.htmlpart替换为cities.txt中相应的城市代码。然后weatherdata字段将以我们可以读取的格式显示API提供的信息

到目前为止,我复制到我的脚本中。我的按钮代码如下所示:

101010100=Beijing
101010300=Chaoyang
101010400=Shuangyi
101010500=Huairou
101010600=Tongzhou
101010700=Changping
101010800=Yanqing
on mouseUp
  put the text of fld "city" into tCityName
  put specialFolderPath("desktop") & "/cities.txt" into tFilePath
  put textDecode(tCityList,"UTF8") into tCityList 
  put lineOffset("=" & tCityName & cr,tCityList & cr) into tFoundLine
  set the itemDelimiter to "="
  put item 1 of line tFoundLine of tCityList into tCityCode
  put "http://m.weather.com.cn/data/" & tCityCode & ".html" into tURL
  put URL tURL into tRawJSON
  put textDecode(tRawJSON,"UTF8") into fld "weatherdata"
end mouseUp
但是,它不起作用,除非在天气数据字段中显示:

<html>
<head>
</head>
<body>
<script type="text/javascript">
window.onload = function() {
window.open("/","_self");
}; 
</script> 
<!-- START WRating v1.0 -->
<script type="text/javascript" src="http://c.wrating.com/a1.js">
</script>
<script type="text/javascript">
var vjAcc="860010-2151010100";
var wrUrl="http://c.wrating.com/";
vjTrack("");
</script>
<noscript><img src="http://c.wrating.com/a.gif?a=&c=860010-2151010100"width="1" height="1"/>
</noscript>
<!-- END WRating v1.0 -->
</body>
</html>
我真的很困惑,不知道如何解决它,有人能帮我吗


.

这看起来像是暂时的小故障。如果我运行以下脚本

on mouseUp
     put empty
     put url "http://m.weather.com.cn/data/101110101.html" into myData
     put the result into rslt
     put rslt & cr & myData
end mouseUp
我在消息框中获取json数据,可以用EasyJSON解析。偶尔我会在结果中得到HTML代码和/或错误代码。如果发生这种情况,几分钟后再试一次