2
{
      "code": 0,
      "data": {
        "KAVAUSDT": {
          "name": "KAVAUSDT",
          "min_amount": "0.5",
          "maker_fee_rate": "0.003",
          "taker_fee_rate": "0.003",
          "pricing_name": "USDT",
          "pricing_decimal": 4,
          "trading_name": "KAVA",
          "trading_decimal": 8
        },
        "CFXUSDT": {
          "name": "CFXUSDT",
          "min_amount": "5",
          "maker_fee_rate": "0.003",
          "taker_fee_rate": "0.003",
          "pricing_name": "USDT",
          "pricing_decimal": 6,
          "trading_name": "CFX",
          "trading_decimal": 8
        },
        ... continue 
      }
    }

If there were [ and ] symbols, I could solve it quickly with TJsonArray:

...

JsonArray := JsonValue.GetValue<TJSONArray>('data');

for ArrayElement in JsonArray do
begin
  tempName           := ArrayElement.GetValue<String>('name');
  tempPricingName    := ArrayElement.GetValue<String>('pricing_name');   
  ...
end;

There are no [and ] symbols in this Json type.

Without the [ and ] symbols, I cannot access the data, as it is using a for loop.

Is there a simple solution?

1
  • 1
    That's not an array, it's an object Commented Oct 16, 2021 at 3:48

1 Answer 1

7

There is no array in the JSON document you have shown. "KAVAUSDT", "CFXUSDT", etc are not array elements, they are simply named object fields of the "data" object. If you need to loop through the child fields of the "data" object, you can use TJSONObject (not TJSONArray!) for that, eg:

...

JsonObj := JsonValue.GetValue<TJSONObject>('data');

for Field in JsonObj do
begin
  FieldObj           := Field.JsonValue as TJSONObject;
  tempName           := FieldObj.GetValue<String>('name');
  tempPricingName    := FieldObj.GetValue<String>('pricing_name');   
  ...
end;
Sign up to request clarification or add additional context in comments.

2 Comments

{ "code": 0, "data": { "PGN": { "available": "17106.09093508", "frozen": "0" }, "USDT": { "available": "164.43456092", "frozen": "0" } , ... , ... , ... , ... }, "message": "Succeeded" } How Can i read Header key like "PGN" , "USDT" , "???" ....
@AbdullahYılmaz the exact same way I showed in my answer. Field.JsonString is the name (PGN, USDT, etc) and Field.JsonValue is the TJSONObject where available, frozen, etc can be accessed from.

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.