>>>>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...
>>
>>Interesting approach of using Regular Expression. In my view, it is a little 'overkill' since I can search the string for a key word (e.g. ["Version":]). I thought I was missing some built-in VFP function. But if you didn't see it, it means it does not exist.
>>Thank you!
>
>
>I first thought about using a combination of strextract and alines to parse, but what is the fun of it? :)
Actually for me using alines (which I have not thought about prior to you mentioning it, but now I will) is fun enough :).
I am still an apprentice :)
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham