2013-08-20 7 views
1

답변을 검색하고 있지만 couldent가 저를 찾았습니다. 임 사용 발리 - JSON 요청 메신저 점점 오류 : java.lang.IllegalStateException :gson으로 json 파일을 구문 분석 할 때 오류가 발생했습니다.

public class GameStatusResponse 
{ 
public Meta meta; 
public GameStatusObject response; 

public class GameStatusObject 
{ 
    public ArrayList<GameStatus> GameStatusGames; 
} 
} 
: 이것은 내 대답 클래스는

public static JsonTask<GameStatusResponse> PostLiveGames(final Context ctx, ArrayList<GameStatus> liveGames) 
{ 
    ArrayList<Integer> gamesIds = new ArrayList<Integer>(); 
    for (GameStatus gameStatus : liveGames) 
    { 
     gamesIds.add(gameStatus.ID); 
    } 

    JsonObject bodObj = new JsonObject(); 
    bodObj.addProperty("AcceptNotification", true); 
    bodObj.addProperty("AppVersion", WZApp.getAppVersion(mContext)); 
    String ids = ""; 
    for (int i = 0; i < gamesIds.size(); i++) 
    { 
     ids = ids + "," + gamesIds.get(i); 
    } 

    ids = ids.substring(1, ids.length()); 

    bodObj.addProperty("games", "[" + ids + "]"); 
    System.out.println("live games object: " + bodObj.toString()); 

    JsonTask<GameStatusResponse> task = new JsonTask<GameStatusResponse>(getURL(APIMethods.GetLiveGames.url), 
      GameStatusResponse.class, new JsonResponseCallback<GameStatusResponse>() 
      { 

       @Override 
       public void onResponseReceived(GameStatusResponse response) 
       { 
        if (response != null && response.response != null 
          && response.response.GameStatusGames.size() > 0) 
         System.out.println("check " + response.response.GameStatusGames.get(0).GameStatusType); 
       } 

       @Override 
       public void onErrorReceived(Exception error) 
       { 
        System.out.println("we got error in live games: " + error.getMessage()); 

       } 
      }); 
    task.addCustomDeserializer(betStatusTypeDeserializer, DataEnums.BetStatusType.class) 
      .addCustomDeserializer(betResultTypeDeserializer, BetResult.class) 
      .addCustomDeserializer(gameStatusTypeDeserializer, DataEnums.WZGameStatusType.class) 
      .addCustomDeserializer(jinxTypeDeserializer, DataEnums.JinxType.class) 
      .addCustomDeserializer(betOddsOutcomesTypeDeserializer, DataEnums.WZOddsOut.class) 
      .addCustomDeserializer(betOddsTypeDeserializer, DataEnums.WZOdds.class); 

    task.setAuthHeader(buildAuthHeader(RequestType.Flow, mDataManager.getCurrUser())).setPostMethod(bodObj); 

    if (WZApp.debugMode) 
     task.setDebugMode(true); 

    task.execute(); 

    return task; 

입니다 : 예상 BEGIN_OBJECT하지만이 내 코드입니다 BEGIN_ARRAY

했다

나의 등급 :

import java.util.ArrayList; 
    import android.os.Parcel; 
    import android.os.Parcelable; 
    import com.j256.ormlite.field.DataType; 
    import com.j256.ormlite.field.DatabaseField; 
    import com.j256.ormlite.table.DatabaseTable; 
    import com.moblin.wagerzone.DataEnums; 
    @DatabaseTable 
    public class GameStatus implements Parcelable 
    { 
@DatabaseField 
public int ID; 

@DatabaseField 
public int T1_Result; 

@DatabaseField 
public int T2_Result; 

@DatabaseField 
public int TotalBets; 

@DatabaseField 
public boolean isEnded; 

@DatabaseField 
public int WinnerID; 

@DatabaseField 
public int GameResult; 

@DatabaseField 
public DataEnums.WZGameStatusType GameStatusType; 

@DatabaseField(dataType = DataType.SERIALIZABLE, canBeNull = true) 
public ArrayList<Odd> Odds; 

public int priority; 

public GameStatus() 
{ 
} 

public GameStatus(Parcel in) 
{ 
    this.GameResult = in.readInt(); 
    this.WinnerID = in.readInt(); 
    this.TotalBets = in.readInt(); 
    this.ID = in.readInt(); 
    this.T1_Result = in.readInt(); 
    this.T2_Result = in.readInt(); 
    this.GameStatusType = DataEnums.WZGameStatusType.getById(in.readInt()); 
    boolean[] temp = new boolean[1]; 
    try 
    { 
     in.readBooleanArray(temp); 
    } catch (Exception e) 
    { 
     // TODO: handle exception 
    } 

    isEnded = temp[0]; 
    if (Odds != null) 
     in.readTypedList(Odds, Odd.CREATOR); 
} 

@Override 
public int describeContents() 
{ 
    // TODO Auto-generated method stub 
    return 0; 
} 

@Override 
public void writeToParcel(Parcel dest, int flags) 
{ 
    dest.writeTypedList(Odds); 
    dest.writeInt(this.WinnerID); 
    dest.writeInt(this.GameResult); 
    if (GameStatusType != null) 
     dest.writeInt(this.GameStatusType.id); 

    dest.writeInt(this.TotalBets); 

    dest.writeInt(this.ID); 

    dest.writeInt(this.T1_Result); 
    dest.writeInt(this.T2_Result); 
    dest.writeBooleanArray(new boolean[] { isEnded }); 

} 

@SuppressWarnings("rawtypes") 
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() 
{ 
    public GameStatus createFromParcel(Parcel in) 
    { 
     return new GameStatus(in); 
    } 

    public GameStatus[] newArray(int size) 
    { 
     return new GameStatus[size]; 
    } 
}; 

public boolean isLive(GameStatus gameStatus) 
{ 
    boolean retval = false; 
    switch (gameStatus.GameStatusType) 
    { 
     case WZGameStatusCancelled: 
      break; 
     case WZGameStatusEnded: 
      break; 
     case WZGameStatusLive: 
      retval = true; 
      break; 
     case WZGameStatusNew: 
      break; 
     case WZGameStatusWaiting: 
      break; 
     default: 
      break; 

    } 
    return retval; 
} 

}

및 로그 고양이 :

response: 
{ 
    meta =  { 
     message = OK; 
     "operation_message" = "<null>"; 
     operationstatus = 0; 
     status = 200; 
    }; 
    response =  (
       { 
      GameResult = 3; 
      GameStatusType = 3; 
      ID = 106448; 
      Odds =    (
           { 
        OddID = 84001; 
        Outcomes =      (
               { 
          ID = 4; 
          Name = 1; 
         }, 
               { 
          ID = 5; 
          Name = X; 
         }, 
               { 
          ID = 6; 
          Name = 2; 
         } 
        ); 
        Result = "<null>"; 
        TypeID = 10; 
        TypeName = ThreeWay; 
        Value = "<null>"; 
       } 
      ); 
      "T1_Result" = 0; 
      "T2_Result" = 0; 
      TotalBets = 76; 
      WinnerID = "<null>"; 
      isEnded = 0; 
     }, 
       { 
      GameResult = 3; 
      GameStatusType = 3; 
      ID = 107009; 
      Odds =    (
           { 
        OddID = 85377; 
        Outcomes =      (
               { 
          ID = 7; 
          Name = 1; 
         }, 
               { 
          ID = 8; 
          Name = 2; 
         } 
        ); 
        Result = "<null>"; 
        TypeID = 20; 
        TypeName = TwoWay; 
        Value = "<null>"; 
       } 
      ); 
      "T1_Result" = 0; 
      "T2_Result" = 0; 
      TotalBets = 0; 
      WinnerID = "<null>"; 
      isEnded = 0; 
     }, 
       { 
      GameResult = 3; 
      GameStatusType = 4; 
      ID = 107087; 
      Odds =    (
           { 
        OddID = 85539; 
        Outcomes =      (
               { 
          ID = 7; 
          Name = 1; 
         }, 
               { 
          ID = 8; 
          Name = 2; 
         } 
        ); 
        Result = "<null>"; 
        TypeID = 20; 
        TypeName = TwoWay; 
        Value = "<null>"; 
       } 
      ); 
      "T1_Result" = 0; 
      "T2_Result" = 0; 
      TotalBets = 0; 
      WinnerID = "<null>"; 
      isEnded = 0; 
     } 
    ); 
} 

내가 그것을 파악하지 못할, 알려 주시기 바랍니다 :

08-20 10:28:04.485: I/System.out(26524): we got error in live games: Error parsing JSON: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 96 

도 여기 서버에서 JSON이다.

감사합니다.

+0

붙여 넣은 JSON이 올바른지 확인하십시오. JSONLint에서 시도했기 때문에 구문 분석 오류가 발생합니다. –

+0

응답은 JSON이 아닙니다. 문자열은 항상 따옴표가 아닌 =, 세미콜론, ... – Henry

+0

어떻게 응답 코드를 변경해야합니까? thx 헨리. – SacreDeveloper

답변

0

출력이 이상하게 보입니다. JSON 결과가 귀하가 작성한 것입니까?

responseOdd 필드는 모두 [ ] 대신에 ()으로 시작하는 것 같습니다. 게다가 JSON이 전혀 유효하지 않은 것 같습니다.

JSON에서는 을 사용하지 않고 :을 사용하며 필드는 , 대신 ;으로 구분됩니다. 예 :

{ 
    meta : { 
     message : OK, 
     "operation_message" : "<null>", 
     operationstatus : 0, 
     status : 200, 
    }, 
    response : [{ 
     GameResult : 3, 
     GameStatusType : 3, 
     ID : 106448, 
     Odds : [{ 
      OddID : 84001, 
      Outcomes : [{ 
       ID : 4, 
       Name : 1 
      }, { 
       ID : 5, 
       Name : X 
      }, { 
       ID : 6, 
       Name : 2 
      }], 
      Result : "<null>", 
      TypeID : 10, 
      TypeName : ThreeWay, 
      Value : "<null>" 
     }], 
     "T1_Result" : 0, 
     "T2_Result" : 0, 
     TotalBets : 76, 
     WinnerID : "<null>", 
     isEnded : 0 
    }, { 
    .... 
+0

안녕하세요. 덧글은 thx입니다. 이것은 내가 서버에 액세스하지 못하는 출력입니다. 내 코드가 작동하도록 할 수있는 변경 사항이 있습니까? – SacreDeveloper

+0

JSON 라이브러리로 파싱 할 수 없습니다. 최악의 경우,이 포맷을위한 파서를 찾지 못한다면 (즉 독점 포맷 인 경우) 독자적인 파서를 작성해야합니다 (** 정규식과 함께하지 않고 규칙을 따르는 자체 Tokenizer 작성하기) 이 형식을 사용하고 사용할 수있는 것으로 파싱하십시오.) – Tseng

+0

좋습니다, 감사합니다. 나는 그것을 시도 할 것이다. – SacreDeveloper

관련 문제