Alex Rivera | Logout

Delphi: JSON array

Asked 2012-05-11T10:49:24.260
9

Trying to understand the JSON in Delphi. Using the module "DBXJSON.pas". How to use it to make this such an array:

Array:[
        {"1":1_1,"1_2_1":1_2_2},
        ...,
   ]

Doing so:

JSONObject:=TJSONObject.Create;
JSONArray:=TJSONArray.Create();
...
JSONArray.AddElement(TJSONObject.Create(TJSONPair.Create('1','1_1')));
JSONArray.AddElement(TJSONObject.Create(TJSONPair.Create('1_2_1','1_2_2')));
JSONObject.AddPair('Array',JSONArray);

, but get this:

{
"Array":[
{"1":"1_1"},{"1_2_1":"1_2_2"}
]
}

Please help! Thanks!

Edit
Report

1 Answer

-1

Same answer as @teran:

change:

JSONArray.AddElement(TJSONObject.Create(TJSONPair.Create('1','1_1')));
JSONArray.AddElement(TJSONObject.Create(TJSONPair.Create('1_2_1','1_2_2')));

to:

JSONArray.AddElement(TJSONPair.Create('1','1_1'));
JSONArray.AddElement(TJSONPair.Create('1_2_1','1_2_2'));

Cheers.

answered 2012-05-11T14:40:03.593

Your Answer