ParseJSON How to parse json array

I am very new to json in Xojo so I need some newby help.
I am trying to parse a json response. In ContentReceived, I am trying to parse the json in “content”.
I need to get the values in “value”:PLUG-SPARK and “itemprice”:1.3
I tried this.

var a() as variant
a = ParseJSON(content)

but I get an error
Here is the long json string that is returned in “content”.

{“errors”:,“pa”:[{“inv”:[{“qty”:1,“wh”:1}],“item”:{“attributes”:[{“name”:“Description”,“value”:“PLUG - SPARK”},{“name”:“Description2”,“value”:“”},{“name”:“IsHAZ”,“value”:“False”},{“name”:“IsNON”,“value”:“False”},{“name”:“Backorderable”,“value”:“True”},{“name”:“Weight”,“value”:“0.16”}],“itemnumber”:“TSA/SY188T”},“itemerror”:null,“price”:{“coreprice”:0,“currency”:“USD”,“itemprice”:1.3,“listprice”:2.05,“qtybreaks”:[{“price”:1.3,“qtycount”:1}]},“reqitem”:{“id”:“TestId”,“itemnumber”:“sy188t”,“quantity”:1,“reference”:“TestRef”,“wh”:1}}],“requestkey”:“Test3”}

that JSON is not an array, but an object, so don’t define a with array of variant.

dim a as variant

may help.

You’ll need to find the parts you want in the appropriate sections. This code should do it:

Var jsonDict As Dictionary = ParseJSON(content)

Var paArray() As Variant = jsonDict.Value("pa")

Var pa As Dictionary = paArray(0)

Var item As Dictionary = pa.Value("item")

Var attr() As Variant = item.Value("attributes")

Var first As Dictionary = attr(0)

Var value As String = first.Value("value")

Var price As Dictionary = pa.Value("price")
Var itemPrice As Double = price.Value("itemprice")

MessageBox(value + " " + itemPrice.ToString)
1 Like

Thanks Paul, That was exactly what I needed.