Parsing JSON from Google Distance Matrix API with Corona SDK -


So I'm trying to pull data from a JSON string (as seen below ). When I try to index decode by using the code below, and then duration text , I get a zero return is. I have tried to do everything and nothing seems to work.

[{"Element": [{"distance": {"text": "quality": "value": "United States of America"], "original_range": ["Seattle, WA, USA"], "lines" Value ":" period ": {" text ":" 12 hours 18 minutes "," value ": 44303}," position ":" right "}]}]," position ":" right "}

And here is my code:

  local json = need ("json") local http = need ("socket http") local myNewData1 = {} local service data 1 = Away from the function (event) Radiation = "" distance = "" local URL1 = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=Seattle&destinations = San Francisco & Mode = driving & sensor = false "Local response 1 = Http.request (URL1) Local data2 = json.decode (response1) if response1 == Zero then native Shawelert ("Data is Nile", {"OK"}) print ("Error 1") Distance = "Error 1" Other Data2 == Return to Distance = "Error2" native.showAlert ("Data is Null" {"OK"}) print ("Error 2") and for i = 1, # data2 print ("working") print (data 2 [i] .rows) for j = 1, # data2 [i]. Kows = 1, # data2 [i] rows [r] for rows, 1 print ("\ t" .. data2 [i] .rows [j]). 1, # data2 [i] for .rows [of], [1] # [2] [original] [b]. Kashmir]. 1, # 1 for data [I], print ("\ t" .. data 2 [i] .rows [k] .elements [k] .duration [g]). Rows [k] .details [g] .text, 1 print ("\ t". Data 2 [i] .rows [k] .elements [k] .duration [g] .text) distance = Data2 [i] .rows [k]. E. Lements [k] .duration [g] .text distanceReturn = data2 [i] .rows [k] .elements [k] .duration [g] .text end end end end end timer.performWithDelay (100, service 1, 99 99 99)  

Your ends are not correct I try this short solution.

Change all your "i = 1, # data2 do" loop for this one below:

  For print ("working") i, ipar In the row (Data 2. ROS) for J, print the element (line.Alements) in the iPhone (element.rerence.text) end and end  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -