As the title says... Chat on...

User avatar
By zooto68
#10919 According to this page...

http://lua-users.org/wiki/PatternsTutorial

In the 'Captures' section is this code...

Code: Select alldate = "04/19/64"
m, d, y = string.match(date, "(%d+)/(%d+)/(%d+)")
print(m)
print(d)
print(y)


it works fine with the contents of 'date' and returns:

4
19
64

Yet if I try to pass it a json string such as this...

Code: Select all"sun_phase": {
      "sunrise": {
      "hour":"6",
      "minute":"49"
      },
      "sunset": {
      "hour":"17",
      "minute":"34"
      }


I get...

nil
nil
nil

Anybody know why please?
User avatar
By joe
#10922 very hard to tell what you are trying to do here, or why you would want to do it this way but:

Code: Select alla=[["sun_phase": {"sunrise": {"hour":"6","minute":"49"},"sunset": {"hour":"17""minute":"34"}}]]
=string.match(a, [["sunrise": {"hour":"(%d+)","minute":"(%d+)"]])
6   49
User avatar
By zooto68
#10925 I'm trying to parse a json string to get the numbers out:

e.g. JSOn string from Wunderground API...

Code: Select all{
  "response": {
  "version":"0.1",
  "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
  "features": {
  "astronomy": 1
  }
   }
      ,   "moon_phase": {
      "percentIlluminated":"72",
      "ageOfMoon":"9",
      "phaseofMoon":"Waxing Gibbous",
      "hemisphere":"North",
      "current_time": {
      "hour":"21",
      "minute":"35"
      },
      "sunrise": {
      "hour":"6",
      "minute":"49"
      },
      "sunset": {
      "hour":"17",
      "minute":"34"
      }
   },
   "sun_phase": {
      "sunrise": {
      "hour":"6",
      "minute":"49"
      },
      "sunset": {
      "hour":"17",
      "minute":"34"
      }
   }
}


and I just want the 4 digits that make up the sunrise and sunset information.