2014-09-11 4 views
1

웹 서버에서 Json을 읽을 수있는 XSuperObject를 다운로드했지만 현재 Json 문자열을 ISuperArray에 추가하는 순간 Segmentation 오류가 발생합니다.XSuperObject 분할 오류 11 Delphi XE6

JsonResult : string; 
JsonResult := IdHTTP1.Get('http://.................'); 
LoadJSONXSuperObject(JsonResult); 

procedure TDataForm.LoadJSONXSuperObject(S: String); 
var 
aobj: ISuperArray; 
obj2: ISuperObject; 
I: Integer; 
MyString: String; 
begin 

aobj := SA(S); // RIGHT HERE I GET THE fault (11) or bus (10) 
for I := 0 to aobj.Length-1 do 
    begin 
    end; 

다음 코드는 작동하지만, 17 개 필드가 각 레코드를 읽기 위해 2 초 소요 (800) 내가 그것을 모두 800

try 
    LResult := LJsonObj.Get('d').JsonValue as TJsonObject; 
    LElements := LResult.Get('results').JsonValue as TJsonArray; 

    for i := 0 to LElements.count -1 do 
    begin 
     Try 
     LItem := (LElements.Get(i) as TJsonObject).Get('pbutton').JsonValue as TJsonString; 
     if LItem <> nil then 
      PButton := RemoveQuotes(LItem.ToString) 
     else PButton := ''; 
     except 
      PButton := ''; 
     End; 
     Try 
     LItem := (LElements.Get(i) as TJsonObject).Get('text').JsonValue as TJsonString; 
     if LItem <> nil then 
      InvText := RemoveQuotes(LItem.ToString) 
     else InvText := ''; 
     except 
      InvText := ''; 
     End; 
     Try 
     LItem := (LElements.Get(i) as TJsonObject).Get('buttontext').JsonValue as TJsonString; 
     if LItem <> nil then 
      ButtonText := RemoveQuotes(LItem.ToString) 
     else ButtonText := ''; 
     except 
      ButtonText := ''; 
     End; 
end; 
    finally 

    end; 
10 초 정도 걸립니다 Eclipse에서 동일한 응용 프로그램을이

다음은 Json 파일의 샘플입니다.

당신이 JSON 배열 ( [data, data, data]을)하지 않는 프로그램을 제공
{ 
    "d": { 
     "results": [ 
      { 
       "__metadata": { 
        "uri": "http://myserver", 
        "key_fields": "", 
        "rows_affected": -1, 
        "last_autoinc": 0 
       }, 
       "pbutton": 1, 
       "text": "Pizza", 
       "buttontext": "Pizza", 
       "price1": 10.99 
      }, 
      { 
       "__metadata": { 
        "uri": "http://myserver", 
        "key_fields": "", 
        "rows_affected": -1, 
        "last_autoinc": 0 
       }, 
       "pbutton": 2, 
       "text": "Pizza 2", 
       "buttontext": "Pizza 2", 
       "price1": 10.99 
      }, 
      { 
       "__metadata": { 
        "uri": "http://myserver", 
        "key_fields": "", 
        "rows_affected": -1, 
        "last_autoinc": 0 
       }, 
       "pbutton": 98, 
       "text": null, 
       "buttontext": null, 
       "price1": 0 
      } 
     ] 
    } 
} 
+0

당신이'[...] '이 아니라 개체'{...}를'배열을받을 확신 :

uses XSuperObject, XSuperJSON; procedure TDataForm.LoadJSONXSuperObject(const S: string); var jsonObj, currentObj: ISuperObject; enum: TSuperEnumerator<IJSONAncestor>; begin jsonObj:= SO(S); enum := jsonObj['d.results'].AsArray.GetEnumerator; while enum.MoveNext do begin currentObj := enum.Current.AsObject; PButton := currentObj.I['pbutton']; InvText := currentObj.S['text']; ButtonText := currentObj.S['buttontext']; // Price := currentObj.F['price1']; end; end; 

여기에 X-객체 (superobject) 샘플 참조? 수신 된 JSON 문자열의 예를 추가하십시오. –

+0

질문이 입력 데이터없이 불완전합니다. 질문을 다시 방문하여 하드 코딩 된 입력 데이터가있는 짧은 콘솔 앱으로 변환하십시오. –

+0

감사합니다. Windows에서 재현 할 수 없습니다. 하지만 당신이 다른 플랫폼에서 뛰고있는 것 같아요. 어떤 플랫폼? –

답변