Parse JSON from PHP script

For several years I have worked with Javascript. Xojo is new to me.

In Javascript I make and http call to my php file, which makes a call to the MYSQL DB and the data is returned as a String to the app.

I then run a simple JSON.parse(data) and the string is now JSON.

What is the equivalent in Xojo?

I’ve been messing around with it for several hours and have no problem getting the text back using HTTPSocket.get("http://…)
Also, that appears to be the older, deprecated way of doing things.

Getting the result into JSON has proved difficult for me.

So my question is, What is the best way to convert String text returned from a PHP script on the Server, back into my Desktop App, and then convert it into JSON format?
Thanks for your help.

[quote]Dim socket1 As New HTTPSocket Dim data As String = socket1.Get("http://url.url/json", 30) #Returns as text dim j as new JSONItem(data) #This returns a variable as a jsonitem and data is the text from the url call.. use it as a dictionary msgbox j.ToString #This prints the json as text[/quote]

Variable j is now a jsonitem (nearly identical to a dictionary). The .ToString method allows for it to be printed as JSON text.

Is this what you were looking for?

But isn’t JSONItem deprecated?

The LR is your friend :


JSONItem does have a couple of bugs (that you’d probably never see) that are addressed by the new framework. If you like the way it works but want a faster version that addresses those bugs, try my open-source JSONItem_MTC as a drop-in replacement.

Otherwise, the new framework equivalents of what you want are Xojo.Data.ParseJSON and Xojo.Data.GenerateJSON.

Like this:

dim data as Auto = Xojo.Data.ParseJSON( originalString.ToText )
// data is now either a Xojo.Core.Dictionary or 
// an array of Auto(), depending on the JSON.
// To get it back:

dim out as text = Xojo.GenerateJSON( dictOrArray )