2016-12-11 2 views
1

を使用してPOJO(モデル)クラスを生成することができませんので、私はPOJO(モデル)クラスを作成するためのGson形式のプラグインを使用するが、私はこのためGsonのそれを作成することはできませんよフォーマット例外エラー -私は改修に2.1.0ライブラリを使用してJSONをパースしたいGson形式

com.intellij.util.IncorrectOperationException: Incorrect field '/** 
      * 0 : {"lat":"23.0124","long":"72.5228","question":"caluculate 1+2","hint":"1,2,3","questionAudioUrl":"http://audio/1480919241.mp3"} 
      * type : type1 
      */ 
      @com.google.gson.annotations.SerializedName("0")private 0Bean value0 ; ' 

そして、私のJSONは、私はここでは、このサイトhttp://jsonformatter.org/

を使用して検証していますも有効ですが、私のJSON

{ 
    "response": { 
    "result": true, 
    "errorCode": 0, 
    "errorDescription": "Success", 
    "tourData": { 
     "TourID": "5", 
     "sTourName": "titanium city center ahmedabad", 
     "sShortDescription": "ffjk fdjf fdjf fd f jkdf fjdf fdf f fhfjd fj jfjfjdhfhfhfdf f fjhf", 
     "sLongDescription": "dsd dsd ds dsd dsd d sdsd ds dsd sds dd", 
     "sCity": "ahmedabad", 
     "sLatitude": "23.0124", 
     "sLongitude": "72.5228", 
     "sGoalLat": "-2.09", 
     "sGoalLong": "12.5228", 
     "sVersion": "1", 
     "dDate": "2016-11-29 00:41:32", 
     "status": "APPROVED", 
     "iTourImagesID": "18", 
     "iTourID": "5", 
     "iImageData": "http://myurl/images/tour-images/1480405309background_menu.jpeg", 
     "bIsDefault": "1", 
     "dDateTime": "2016-11-29 13:11:49" 
    }, 
    "tourCountData": { 
     "total_image": "4", 
     "total_coin": "12", 
     "total_diamond": "1", 
     "total_clues": "3", 
     "total_checkpoint": "1" 
    }, 
    "TourAllImageData": [ 
     { 
     "iImageData": "http:///images/tour-images/1480405309background_menu.jpeg", 
     "bIsDefault": "1" 
     }, 
     { 
     "iImageData": "http://images/tour-images/[email protected]", 
     "bIsDefault": "1" 
     }, 
     { 
     "iImageData": "http:///images/tour-images/[email protected]", 
     "bIsDefault": "1" 
     }, 
     { 
     "iImageData": "http://images/tour-images/[email protected]~ipad.jpeg", 
     "bIsDefault": "1" 
     } 
    ], 
    "img_result": true, 
    "TourAllUserData": [], 
    "u_result": false, 
    "TourcoinsData": [ 
     { 
     "sLatitude": "19.422655", 
     "sLongitude": "-99.161297", 
     "iTourPlaceID": "10" 
     }, 
     { 
     "sLatitude": "23.0135", 
     "sLongitude": "72.5228", 
     "iTourPlaceID": "12" 
     }, 
     { 
     "sLatitude": "23.0150", 
     "sLongitude": "72.5296", 
     "iTourPlaceID": "13" 
     }, 
     { 
     "sLatitude": "23.0150", 
     "sLongitude": "72.5245", 
     "iTourPlaceID": "14" 
     }, 
     { 
     "sLatitude": "23.0160", 
     "sLongitude": "72.5310", 
     "iTourPlaceID": "15" 
     }, 
     { 
     "sLatitude": "23.0115", 
     "sLongitude": "72.5228", 
     "iTourPlaceID": "16" 
     }, 
     { 
     "sLatitude": "23.0135", 
     "sLongitude": "72.5296", 
     "iTourPlaceID": "17" 
     }, 
     { 
     "sLatitude": "23.0115", 
     "sLongitude": "72.5200", 
     "iTourPlaceID": "18" 
     }, 
     { 
     "sLatitude": "23.0135", 
     "sLongitude": "72.5270", 
     "iTourPlaceID": "19" 
     }, 
     { 
     "sLatitude": "23.0135", 
     "sLongitude": "72.5260", 
     "iTourPlaceID": "20" 
     }, 
     { 
     "sLatitude": "23.0160", 
     "sLongitude": "72.5296", 
     "iTourPlaceID": "21" 
     }, 
     { 
     "sLatitude": "23.0170", 
     "sLongitude": "72.5310", 
     "iTourPlaceID": "22" 
     } 
    ], 
    "co_result": true, 
    "TourDiamondData": [ 
     { 
     "sLatitude": "23.011487", 
     "sLongitude": "72.525011", 
     "iTourPlaceID": "24", 
     "sPlaceImage": "http:/images/places/1481007650-place.png", 
     "sPlaceDescription": "dd d dh hffh idufhfhf hf hfhd fhf hdfhufh ffdufh fhdfu dfhd fhd fhdfhdufduf hfhdfhd fhdfhdf dfhdufd ffdufh fhdufd ffhduf ufufh" 
     } 
    ], 
    "di_result": true, 
    "TourCheckpointData": [ 
     { 
     "sLatitude": "23.0225", 
     "sLongitude": "72.5714", 
     "iTourPlaceID": "23" 
     } 
    ], 
    "chk_result": true, 
    "TourClueData": [ 
     { 
     "sClues": "clue1" 
     }, 
     { 
     "sClues": "clue2" 
     }, 
     { 
     "sClues": "clue3" 
     } 
    ], 
    "clu_result": true, 
    "TourChallenge1Data": { 
     "0": { 
     "lat": "23.0124", 
     "long": "72.5228", 
     "question": "caluculate 1+2", 
     "hint": "1,2,3", 
     "questionAudioUrl": "http://audio/1480919241.mp3" 
     }, 
     "type": "type1" 
    }, 
    "TourChallenge2Data": { 
     "0": { 
     "lat": "23.0143", 
     "long": "72.5296", 
     "question": "type2", 
     "hint": "1,,,2", 
     "timer": "01:01:00", 
     "questionAudioUrl": "http://audio/1480919413.mp3" 
     }, 
     "type": "Type2" 
    }, 
    "TourChallenge3Data": { 
     "0": { 
     "lat": "23.011641", 
     "long": "72.523917", 
     "puzzleImageUrl": "http:/images/puzzles/1480919458-puzzle.png", 
     "puzzleDescription": "set image", 
     "puzzleAudioUrl": "http:/audio/1480919458.mp3" 
     }, 
     "type": "Type3" 
    }, 
    "TourChallenge4Data": { 
     "0": { 
     "lat": "23.0124", 
     "long": "72.5210", 
     "keyLat": "23.0135", 
     "keyLong": "72.5228" 
     }, 
     "type": "Type4" 
    } 
    } 
} 
0123です

私はhttp://www.jsonschema2pojo.org/はモデルクラスを生成することがある知っているが、それはそれは非常に多くのクラスを管理するのは難しいので、クラスをネストされていない別のクラスを作成します。

QUE 1: jsonを使用してモデルクラスを生成するにはどうすればよいですか?

QUE 2:は私がRequestBodyを試みたが、動作しない私は改造2.1.0を使用して文字列の応答を得ることができる方法はあります。

そのための任意のより良い解決策はあります?

+0

あなたは、その発電機から返されるオブジェクトは、私は –

答えて

1

enter image description here

enter image description here

これはあなたのJSONのサンプルその方法としてみてください、それをチェックobject.Pleaseです。

+0

が @POST( "index.phpを/ App_controller/googleuser_login") コール google_login(@FieldMapのHashMap <文字列、オブジェクトを@FormUrlEncoded信じて巣に許可されています> hashMap); – Lovekesh

+0

これは)({) Utility.hideProgressHudをボディオブジェクト – Lovekesh

+0

.enqueue(新しいコールバック(){@Override ます。public void onResponse(コール呼び出し、レスポンス応答を取得する方法です。 String responseString = response.body()。string(); – Lovekesh

0

1)私はGsonフォーマッタプラグインに慣れていませんが、無効なタイプ名 "0Bean"を生成しているようです。あなたはそれが生成するものの名​​前とタイプを編集することができますように見えます。それ以外の場合は、POJOをコーディングあなたが言及したサイトまたは手を使用すると、オプションです。あなたのJSON内の要素の名前を変更することができますが、場合にも、「0」のような数字のフィールドに名前を付けないでください。

Retrofit retrofit = new Retrofit.Builder() 
    .baseUrl(/* your url */) 
    .addConverterFactory(ScalarsConverterFactory.create()) 
    .addConverterFactory(GsonConverterFactory.create()) /* if you also still need GSON, if not, you can leave this off */ 
    .build(); 

とあなたのインターフェイスに - -

@GET("/mypath") 
Call<String> getMyStuff(); 

あなたが追加する必要があります - compile 'com.squareup.retrofit2:converter-scalars:2.1.0'をあなたのGradleに

2)あなたは、スカラーコンバータを使用して、文字列の応答を得ることができますファイル。

+0

しかし、場合によってはGsonConverterが必要です –

+0

上記のコードのように2つのコンバータを使用できます。最初のコンバーターが優先されますが、基本型(String、int、float、doubleなど)のみが変換されます。 gsonコンバータを使用する他のクラスを指定します。 – iagreen

+0

ScalarsConverterFactoryはPOJOだけでなく、単一の変数でも動作しますか? –

関連する問題