I want to produce something like this:
{
"nrVendas": 2,
"totalVendas": 100.0,
"vendas": [
{
"nsuOrigem": "1",
"data": "2014-03-14",
"nrParcelas": 1,
"valor": 50,
"parcelas": [
{
"numero": 1,
"valor": 50
}
]
},
{
"nsuOrigem": "2",
"data": "2014-03-14",
"nrParcelas": 1,
"valor": 50,
"parcelas": [
{
"numero": 1,
"valor": 50
}
]
}
]
}
I'm trying it this way:
js3 := TlkJSONobject.Create;
js3.Add('numero', '1');
js3.Add('valor', '50');
js32 := TlkJSONobject.Create;
js32.Add('numero', '1');
js32.Add('valor', '100');
js2 := TlkJSONobject.Create;
js2.Add('nsuOrigem', '1');
js2.Add('data', '2014-02-02');
js2.Add('nrParcelas', 1);
js2.Add('valor', 50);
js2.Add('parcelas', js3);
js2.Add('nsuOrigem', '2');
js2.Add('data', '2014-02-02');
js2.Add('nrParcelas', 1);
js2.Add('valor', 50);
js2.Add('parcelas', js32);
js0 := TlkJSONobject.Create;
js0.Add('numeroVendas', 2);
js0.Add('totalVendas', 100.0);
js0.Add('vendas', js2);
i := 0;
s := GenerateReadableText(js0, i);
Memo2.Lines.Add(s);
But I'm receiving this instead:
{
"numeroVendas": 2,
"totalVendas": 100,
"vendas": {
"nsuOrigem": "1",
"data": "2014-02-02",
"nrParcelas": 1,
"valor": 50,
"parcelas": {
"numero": "1",
"valor": "50"
},
"nsuOrigem": "2",
"data": "2014-02-02",
"nrParcelas": 1,
"valor": 50,
"parcelas": {
"numero": "1",
"valor": "100"
}
}
}
Then I try to validade this JSON, but i received this error:
SyntaxError: Duplicate key 'nsuOrigem' on line 13
I think I need to use an array on the fields inside vendas
, but I searched in all of the documentation and more, but I can't find anything that can help me.