I'm using Delphi XE2, I have this json struct to create:
[
{
"Email": "laura@yyyy.com",
"MobileNumber": "",
"MobilePrefix": "",
"Name": "Laura",
"Fields": [
{
"Description": "nominativo",
"Id": "1",
"Value": "Laura"
},
{
"Description": "societa",
"Id": "2",
"Value": ""
},
{
"Description": "idcontatto",
"Id": "3",
"Value": "0"
}
]
},
{
"Email": "paolo@xxxx.com",
"MobileNumber": "",
"MobilePrefix": "",
"Name": "Paolo",
"Fields": [
{
"Description": "nominativo",
"Id": "1",
"Value": "Paolo"
},
{
"Description": "societa",
"Id": "2",
"Value": ""
},
{
"Description": "idcontatto",
"Id": "3",
"Value": "1"
}
]
}
]
I did several tests with superobject but have not yet arrived at the correct result because I get the first element of the array equal to the second. My difficulty is in iteration and optimization. This is the code I'm working on:.
json := TSuperObject.Create;
jsonArray:= TSuperObject.Create(stArray);
json.S['Email'] := 'laura@yyyy.com';
json.S['MobileNumber'] := '';
json.S['MobilePrefix'] := '';
json.S['Name'] := 'Laura';
json['Fields'] := SA([]);
json_Fields:=SO;
json_Fields.S['Description']:='nominativo';
json_Fields.S['Id']:='1';
json_Fields.S['Value']:='Laura';
json.A['Fields'].Add(json_Fields);
json_Fields:=SO;
json_Fields.S['Description']:='societa';
json_Fields.S['Id']:='2';
json_Fields.S['Value']:='';
json.A['Fields'].Add(json_Fields);
//......other fields
JsonArray.AsArray.Add(json);
json.S['Email'] := 'paolo@xxxx.com';
json.S['MobileNumber'] := '';
json.S['MobilePrefix'] := '';
json.S['Name'] := 'Paolo';
json['Fields'] := SA([]);
json_Fields:=SO;
json_Fields.S['Description']:='nominativo';
json_Fields.S['Id']:='1';
json_Fields.S['Value']:='Paolo';
json.A['Fields'].Add(json_Fields);
json_Fields:=SO;
json_Fields.S['Description']:='societa';
json_Fields.S['Id']:='2';
json_Fields.S['Value']:='';
json.A['Fields'].Add(json_Fields);
//......other fields
JsonArray.AsArray.Add(json);
jsonArray.SaveTo('json_mu.txt');