0

I use C++Builder XE6 Pro and have the following JSON response (see the full response here):

[
{
"id":"10186",
"dataset":"krs_podmioty",
"url":"https://api-v3.mojepanstwo.pl/dane/krs_podmioty/10186",
"mp_url":"https://mojepanstwo.pl/dane/krs_podmioty/10186",
"schema_url":"https://api-v3.mojepanstwo.pl/schemas/dane/krs_podmioty.json",
"global_id":"3157847",
"slug":"bank-millennium",
"score":12.13878,
"data":
{
  "krs_podmioty.nazwa_organu_reprezentacji":"ZARZĄD",
  "krs_podmioty.dotacje_ue_beneficjent_id":"0",
  "krs_podmioty.liczba_prokurentow":0,
  ...
  "gpw":true
}
...
]

I am using REST components, but when I try to parse this, both in the REST Debugger and at design/run-time, I am getting empty values for the "dataset":"krs_podmioty" elements, but the "gpw":true elements show correctly.

I've choosen the JSON root element as DataObject, and marked Nested and set NestedElementDepth to 3. I have tried another settings as well, but without success.

How to get the "dataset":"krs_podmioty" values correctly ?

3
  • UTF-8 encoding issue of some accentuated characters? Commented Apr 14, 2017 at 11:49
  • Arnaud Bouchez: Doubt it, parsing didn't fail since i am getting "data":"gpw" proper value wchich is last on the list. Commented Apr 14, 2017 at 13:00
  • XE6 JSON parser is so odd that it may gracefully fail... ;) Commented Apr 14, 2017 at 13:15

1 Answer 1

1

This is how I'm able to read those values:

uses
  System.Json;

procedure TForm1.Button1Click(Sender: TObject);
var
 jsonText: string;
 jsonArray: TJsonArray;
 dataObj: TJsonObject;
 Jobj: TJsonObject;
 krsPodmiotyNazwaOrganuReprezentacjiValue: TJsonValue;
 krsPodmiotyDotacjeUeBeneficjentIdValue: TJsonValue;
 krsPodmiotyLiczbaProkurentowValue: TJsonValue;
begin
 jsonText := '[{Your JSON content here}]';
 Jobj := TJSONObject.ParseJSONValue(jsonText) as TJsonObject;
 jsonArray :=Jobj.GetValue('Dataobject') as TJsonArray;
 dataObj := (jsonArray.Items[0] as TJsonObject).GetValue('data') as  TJsonObject;
  krsPodmiotyNazwaOrganuReprezentacjiValue := dataObj.GetValue('krs_podmioty.nazwa_organu_reprezentacji');
  krsPodmiotyDotacjeUeBeneficjentIdValue := dataObj.GetValue('krs_podmioty.dotacje_ue_beneficjent_id');
  krsPodmiotyLiczbaProkurentowValue := dataObj.GetValue('krs_podmioty.liczba_prokurentow');
  MessageDlg(krsPodmiotyNazwaOrganuReprezentacjiValue.Value, mtInformation, [mbOK], 0, mbOK);
  MessageDlg(krsPodmiotyDotacjeUeBeneficjentIdValue.Value, mtInformation, [mbOK], 0, mbOK);
  MessageDlg(krsPodmiotyLiczbaProkurentowValue.Value, mtInformation, [mbOK], 0, mbOK);
end;

However, if you are not using anything from the System.Json namespace, this might not answer your question.

Sign up to request clarification or add additional context in comments.

1 Comment

Edited to actually compile and run , kinda hoped for dataset solution but documentation states that not every data object could be mapped as DataSet so i assume this is the case. Anyway accepting answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.