[Solved] Structure for a json needed

Just starting out? Need help? Post your questions and find answers here.
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

[Solved] Structure for a json needed

Post 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
Last edited by infratec on Fri Feb 27, 2015 3:08 pm, edited 1 time in total.
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Structure for a json needed

Post 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
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Structure for a json needed

Post 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
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: [Solved] Structure for a json needed

Post by Little John »

Bernd, you are welcome!
I wish you a nice weekend. :-)
Post Reply