#1 2013-02-15 07:20:05

ebz
Member
Registered: 2011-07-20
Posts: 18

Decode JSON Array of multiple object

I'm new using this framework, how to decode array of multiple json? I've tried using such code:

 JSONDecode(jsonText,['x','w','d'],hasil,true);

But I only get the last object value

Example JSON is

[{
		"x" : 2546,
		"w" : "kibik",
		"d" : "<b>kubik<\/b>"
	}, {
		"x" : 14564,
		"w" : "kubik<sup>1<\/sup>",
		"d" : "data two"
	}, {
		"x" : 100,
		"w" : "kubik<sup>2<\/sup>",
		"d" : "string three"
	}
]

Offline

#2 2013-02-17 14:55:36

ebz
Member
Registered: 2011-07-20
Posts: 18

Offline

#3 2013-02-17 15:23:07

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: Decode JSON Array of multiple object

smile

Our JSONDecode() functions do process the content in-place, and expect one object at a time.
It does not have any "DOM-like" trees, as other parsers do. But it is the reason why it is so fast, by the way.

For you request, to decode such JSON object arrays, you can use a TObjectList, providing the class instance to JSONToObject() function - it will read all objects using published properties of the supplied class.
No need to populate an intermediate DOM.

Offline

#4 2013-02-17 15:43:03

ebz
Member
Registered: 2011-07-20
Posts: 18

Re: Decode JSON Array of multiple object

Thank you ab..
I'll try using TObjectList, I always follow this fw development and always amaze with it
Super fast, not depend on DB unit or another new features in D2007.. XE, XE2... (so I can work using my old Delphi 7), unicode support, plus the documentation is 'wow'..  And another what I wonder is that almost all of this framework was develop by single person..

Even sometimes I can't figure yet or find the way to solve my problem using mORMot
(Usually I just coding using procedural type)

Last edited by ebz (2013-02-17 15:46:04)

Offline

#5 2013-02-17 16:21:25

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: Decode JSON Array of multiple object

Yes, this is a major mind break to switch from a procedural type to OOP and interfaces.
But not difficult.

I suspect most of your procedural code is some kind of "object oriented": that is, you apply a function over a reference to some data - which is just some kind of "flattened OOP", like SQLite3, Windows or Linux API.

But I'm not alone on mORMot any more: even if I'm the main developer, I've already received amazing contributions.
So stay tuned, a lot of amazing stuff is coming!

Offline

Board footer

Powered by FluxBB