Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert an array string to VFP cursor/array
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01646369
Message ID:
01646376
Views:
102
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform