1

I apologies, I am new in Livecode and i have no coding experience. I am trying to extract wunderground hourly json data in livecode, but i can't

JSON Data:

"response": {
  "version":"0.1",
  "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
  "features": {
  "hourly": 1
  }
 }
  ,
 "hourly_forecast": [
  {
  "FCTTIME": {
  "hour": "12","hour_padded": "12","min": "00","min_unpadded": "0","sec": "0","year": "2017","mon": "9","mon_padded": "09","mon_abbrev": "Sep","mday": "12","mday_padded": "12","yday": "254","isdst": "0","epoch": "1505196000","pretty": "12:00 PM +06 on September 12, 2017","civil": "12:00 PM","month_name": "September","month_name_abbrev": "Sep","weekday_name": "Tuesday","weekday_name_night": "Tuesday Night","weekday_name_abbrev": "Tue","weekday_name_unlang": "Tuesday","weekday_name_night_unlang": "Tuesday Night","ampm": "PM","tz": "","age": "","UTCDATE": ""
  },
  "temp": {"english": "85", "metric": "29"},
  "dewpoint": {"english": "77", "metric": "25"},
  "condition": "Thunderstorm",
  "icon": "tstorms",
  "icon_url":"http://icons.wxug.com/i/c/k/tstorms.gif",
  "fctcode": "15",
  "sky": "75",
  "wspd": {"english": "4", "metric": "6"},
  "wdir": {"dir": "S", "degrees": "185"},
  "wx": "Thunderstorms",
  "uvi": "11",
  "humidity": "77",
  "windchill": {"english": "-9999", "metric": "-9999"},
  "heatindex": {"english": "94", "metric": "35"},
  "feelslike": {"english": "94", "metric": "35"},
  "qpf": {"english": "0.03", "metric": "1"},
  "snow": {"english": "0.0", "metric": "0"},
  "pop": "61",
  "mslp": {"english": "29.78", "metric": "1008"}
  }
  ,

I copied EasyJSON https://github.com/luxlogica/easyjson into my StackScript. And my button code looks like this:

on mouseUp
   put the text of fld "city" into tCityName
   put the text of fld "country" into tCountry
   
   
put "http://api.wunderground.com/api/dfabb014e63a7457/hourly/q/" &tCountry&"/"&tCityName& ".json" into tURL
put URL tURL into tRawJSON
put textDecode(tRawJSON,"UTF8") into fld "weatherdata"
put arrayFromJson(tRawJSON) into tArray

put tArray["FCTTIME"]["temp"] into fld "Temp"

end mouseUp
proloy
  • 11
  • 2

2 Answers2

0

In version 8 and above there is a JSON library included in LiveCode, which includes two functions: JsonImport and JsonExport. JsonImport converts JSON encoded data to an array.

put the text of fld "city" into tCityName
put the text of fld "country" into tCountry
put "http://api.wunderground.com/api/dfabb014e63a7457/hourly/q/" &tCountry&"/"&tCityName& ".json" into tURL
put URL tURL into tRawJSON
put textDecode(tRawJSON,"UTF8") into fld "weatherdata"
put JsonImport(fld "weatherdata") into tArray
put the keys of tArray into fld "Temp"

There is also a handy tree view widget in v. 8 and higher that makes it easy to visualize the contents of an array. Just drag a tree view widget onto the card from the tools palette and do this:

set the arrayData of widget "tree view" to tArray
Devin
  • 593
  • 1
  • 3
  • 8
0

Thanks Devin for your reply. I got solution:

put tArray["hourly_forecast"][1]["temp"]["metric"] into fld "Temp"
proloy
  • 11
  • 2