Forum > General

[SOLVED] another json problem

(1/1)

superc:
Hello,

I've another json like this

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{        "ProductCode": "aabbcc",        "type": {                "Input": [{                        "A1": {                                "code": 1,                                "LinkDevice": [                                        1, 2, 3                                 ],                                "PosX": 100,                                "PosY": 100                        },                        "A2": {                                "code": 2,                                "LinkDevice": [                                        4, 5, 6, 7, 8                                ],                                "PosX": 100,                                "PosY": 120                        },                        "A3": {                                "code": 3,                                "LinkDevice": [                                        2, 3, 5                                ],                                "PosX": 100,                                "PosY": 140                        }                }],                "Version": "1"        }} 
I must retrieve all data from all element of "Input", like "A1", "A2", "A3" surely they can change and therefore I have to cycle them with an index, but I don't understand how to do it,
 thanks in advance.


paweld:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses  fpjson; procedure TForm1.Button1Click(Sender: TObject);var  jd: TJSONData;  ja: TJSONArray;  jo: TJSONObject;  i, j, k: Integer;begin  Memo2.Lines.Clear;  jd := GetJSON(Memo1.Lines.Text);  if (jd.FindPath('type.Input') <> nil) and (jd.GetPath('type.Input').Count > 0) then  begin    ja := TJSONArray(jd.GetPath('type.Input'));    for i := 0 to ja.Count - 1 do    begin      for j := 0 to ja.Objects[i].Count - 1 do      begin        Memo2.Lines.Add(ja.Objects[i].Names[j]);        jo := TJSONObject(ja.Objects[i].GetPath(ja.Objects[i].Names[j]));        for k := 0 to jo.Count - 1 do        begin          if jo.GetPath(jo.Names[k]).JSONType = jtArray then            Memo2.Lines.Add(Format('    %s is ARRAY', [jo.Names[k]]))          else if jo.GetPath(jo.Names[k]).JSONType = jtObject then            Memo2.Lines.Add(Format('    %s id OBJECT', [jo.Names[k]]))          else            Memo2.Lines.Add(Format('    %s > %s', [jo.Names[k], jo.GetPath(jo.Names[k]).AsString]));        end;      end;    end;  end;  jd.Free;end;  

superc:
it's perfect but i didn't consider one thing: i need to fetch the data of LinkDevice and i would like to massively fetch the array without having to loop it, as if it were a string, is it possible?


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---begin  tl := TStringList.Create;  tl.LoadFromFile(fileJson);   jd := GetJSON(tl.Text);  if (jd.FindPath('type.Input') <> nil) and (jd.GetPath('type.Input').Count > 0) then  begin    ja := TJSONArray(jd.GetPath('type.Input'));    for i := 0 to ja.Count - 1 do    begin      for j := 0 to ja.Objects[i].Count - 1 do      begin        memoDebug.Lines.Add(ja.Objects[i].Names[j]);        jo := TJSONObject(ja.Objects[i].GetPath(ja.Objects[i].Names[j]));        for k := 0 to jo.Count - 1 do        begin          if jo.GetPath(jo.Names[k]).JSONType = jtArray then          begin            jaa := TJSONArray(jo.GetPath(jo.Names[k]));//            memoDebug.Lines.Add(Format('    %s is ARRAY', [jo.Names[k]]))              for h := 0 to jaa.Count-1 do              begin                // concatenate               //inc(cnt);              end;          end          else if jo.GetPath(jo.Names[k]).JSONType = jtObject then            memoDebug.Lines.Add(Format('    %s id OBJECT', [jo.Names[k]]))          else            memoDebug.Lines.Add(Format('    %s > %s', [jo.Names[k], jo.GetPath(jo.Names[k]).AsString]));        end;      end;    end;  end;  jd.Free;end;    
I modified code like this, but I must concatenate... Thanks in advance.

Navigation

[0] Message Index

Go to full version