Page 1 of 1

[Solved] Structure for a json needed

Posted: Fri Feb 27, 2015 2:20 pm
by infratec
Hi,

I get a json string from a shop system, which I want to insert in a structure.

First bad thing was that a field is named data I had no other chance, I had to use #PB_JSON_NoCase.
Ok, solved.

No I get something like that:

Code: Select all

{
 "categories":
 {
  "14":{"id":14,"name":"Edelbr\u00e4nde"},
  "21":{"id":21,"name":"Produktvergleiche & Filter"},
  "50":{"id":50,"name":"Brandies"}
 }
}
I tried all what I know with List and Array, but if I do the other way round, I get always [ ]
and nothing similar to the listing above.

How can I reflect this in a structure, that it is filled by InsertJSONStructure() :?:

Bernd

Re: Structure for a json needed

Posted: Fri Feb 27, 2015 2:59 pm
by Little John
The following works fine. However, maybe there are other possibilities as well.

Code: Select all

Structure Product
   id.i
   name$
EndStructure

Structure Demo
   Map categories.Product()
EndStructure


Define My.Demo

id = 14
AddMapElement(My\categories(), Str(id))
My\categories()\id = id
My\categories()\name$ = "Edelbr\u00e4nde"

id = 21
AddMapElement(My\categories(), Str(id))
My\categories()\id = id
My\categories()\name$ = "Produktvergleiche & Filter"

id = 50
AddMapElement(My\categories(), Str(id))
My\categories()\id = id
My\categories()\name$ = "Brandies"


If CreateJSON(0)
   InsertJSONStructure(JSONValue(0), @My, Demo)
   Debug ComposeJSON(0, #PB_JSON_PrettyPrint)
EndIf

Re: Structure for a json needed

Posted: Fri Feb 27, 2015 3:07 pm
by infratec
Sh..

So I missed to test it with Map :evil:

Because Array and List definately builds something with [ ].

Thanks, Little John :!:

The weekend can start right now :!:

Bernd

Re: [Solved] Structure for a json needed

Posted: Fri Feb 27, 2015 4:12 pm
by Little John
Bernd, you are welcome!
I wish you a nice weekend. :-)