DELPHI/Sample Source

[JSON ArrObject / Sample Source] 제이슨 배열 DATA Parsing 하기

Kim.Sung 2021. 2. 5. 11:34
728x90

※ Delphi 에서 Json Data Parsing 하는법은 검색 해보면 많이 있다.

※ 배열 갯수 와 배열 Data Parsing 하는 Sample Source 이다.

 

1. 수신 데이터

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{
"Parsing":[
{
"Parsing1":"Parsing123030",
"Parsing2":"0010",
"Parsing3":"ParsingGROUP040",
"Parsing4":0,
"Parsing5":"Parsing001040",
"Parsing6":"Lo2040",
"Parsing7":"2021.02.05 11:16:39.868",
"Parsing8":"040",
"Parsing9":"2021.02.05 11:16:39.868",
"Parsing10":"202101290"
},
{
"Parsing1":"Parsing123030",
"Parsing2":"0010",
"Parsing3":"ParsingGROUP040",
"Parsing4":0,
"Parsing5":"Parsing001040",
"Parsing6":"Lo2040",
"Parsing7":"2021.02.05 11:16:39.868",
"Parsing8":"040",
"Parsing9":"2021.02.05 11:16:39.868",
"Parsing10":"202101290"
},
{
"Parsing1":"Parsing123030",
"Parsing2":"0010",
"Parsing3":"ParsingGROUP040",
"Parsing4":0,
"Parsing5":"Parsing001040",
"Parsing6":"Lo2040",
"Parsing7":"2021.02.05 11:16:39.868",
"Parsing8":"040",
"Parsing9":"2021.02.05 11:16:39.868",
"Parsing10":"202101290"
}
]
}
cs

 

2. Parsing Sample Source 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  if Pos('Parsing',sData) <> 0 then
  begin
      //ArrObject  := TJSONArray.Create();
      JsonObject := TJSONObject.create();
      Json_response    := TlkJSONobject.Create();
 
      JsonObject := TJSONObject.ParseJSONValue(sData) as TJSONObject;
      if not (JsonObject = Nil) then
      begin
        ArrObject := TJSONArray.Create;
        Form1.mmo_Data.Lines.add(format('Size=%d',[JsonObject.Size]) );
        ArrObject := TJSONArray( JsonObject.Get('Parsing').JsonValue );
        if not (ArrObject = Nil) then
        begin
 
          Form1.mmo_Data.Lines.add(sData);
          form1.StringGrid1.RowCount := (ArrObject.Size +1);
          MESConunt := ArrObject.Size -1;
          for i := 0 to ArrObject.Size-1 do
          begin
            LItem := ArrObject.Get(i);
            Json_response := TlkJSON.ParseText(LItem.ToString) as TlkJSONobject;
            StringJson := Json_response.Field['Parsing1'] as TlkJSONstring;
            if not (Json_response = Nil) then
            begin
              Parsing1 :=funcChkValue(StringJson.Value);
            end;
            Parsing2 := Json_response.Field['Parsing2'] as TlkJSONstring;
            if not (Json_response = Nil) then
            begin
              Parsing2 :=funcChkValue(StringJson.Value);
            end;
            .... 반복 ...
          end;
        end;
      end;
  end else
  begin
  end;
cs

※ "ArrObject.Size" 수신 받은 DATA 배열 갯수 파악 가능 하다.

728x90