Delphi: Accessing JSON Objects within a JSON Array

前端 未结 2 991
醉梦人生
醉梦人生 2021-01-02 11:15

I have a JSON Object, let\'s name it jObject that looks like this:

{
  \"id\": 0,
  \"data\": \"[{DAT_INCL: \\\"08/03/2012 10:07:08\\\", NUM_ORDE: 1, NUM_ATN         


        
2条回答
  •  鱼传尺愫
    2021-01-02 11:52

    If you have an array from DBXJSON, then it is a TJSONArray. Call its Get method to get an element of the array.

    var
      Value: TJSONValue;
    
    Value := jArray.Get(0);
    

    You can also go through the entire array with a for loop:

    for Value in jArray do
    

    But if you check the Size property and get 6226004 instead of 3, that suggests there's something else wrong here. My guess is that what you think is a TJSONArray isn't really that type. Use as to do a checked type cast:

    jArray := jPair.JsonValue as TJSONArray;
    

    You'll get an EInvalidCast exception if that fails.

提交回复
热议问题