>Hi,
>
>In one place of my app, the response of the Web API call is an "array" (I put the array in quotation marks because this is not exactly a VFP array). The "array" string looks like this:
>
>{"Version":"2.2222","Connected":true}
>
>
>I suppose I can parse this string to get the values. But I was wondering if there is a "better" way to convert this string to an array or a cursor?
>
>TIA
Just a quick solution, probably flawed
clear
local lcToParse, loRE
lcToParse = chrtran(STREXTRACT('{"Version":"2.2222","Connected":true}', '{', '}'), ',', CHR(10))
loRE = createobject('vbscript.regexp')
loRE.Pattern = '"(.+)"\:(.+)'
loRE.IgnoreCase = .t.
loRE.Global = .t.
loMatches = loRE.Execute(lcToParse)
for each loMatch in loMatches
? loMatch.Submatches(0), '=', loMatch.Submatches(1)
endfor
STREXTRACT to remove the {} and then I convert the comma to Line Feeds. Of course this means that this won't work if there are commas that are inside text, i am sure there is a better regular expression, but is Friday...
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?
"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare
"To die for a religion is easier than to live it absolutely"
Jorge L. Borges