2017-11-17 23 views
1
{ 
    "restaurantId":"0a60fa5e-642c-4e4f-ae37-a7c8093e1659", 
    "restaurantName":"Food Market", 
    "paymentRefKey":"cpmqmvpv", 
    "paymentStatus":"success", 
    "paymentMode":"paypal_account", 
    "transactionStatus":"settling", 
    "payerId":"PAYER_ID-2f3c6088eb828dab", 
    "paypalPaymentId":"PAY-e43a2913d8ad92ccda1cf872", 
    "orderNetAmount":"21.825", 
    "salesTax":0, 
    "serviceFee":1.575, 
    "discount":0, 
    "subTotal":22.5, 
    "orderQuantity":1, 
    "userId":"68503c6e-9475-4081-8bdf-199bc194745f", 
    "firstName":"test", 
    "lastName":"customer", 
    "email":"[email protected]", 
    "contactNumber":"9516238470", 
    "couponcode":{ 
     "type":"percent", 
     "midval":2.25, 
     "code":"QDH596" 
    }, 
    "orderLines":[ 
     { 
     "quantity":1, 
     "offerId":"2bb21254-fe7d-4695-ae99-d420fdae3aca", 
     "startValidity":"2017-09-26T06:55:00.000Z", 
     "endValidity":"2017-11-02T01:00:00.000Z", 
     "categoryId":"dbae9249-705a-4d7a-86ce-6f5c5c180855", 
     "itemName":"Dosa.", 
     "menuId":"02bfcaec-0bb1-42b9-87a5-c60e04fcf9fc", 
     "actualPrice":25, 
     "dealPrice":22.5, 
     "netAmount":22.5, 
     "discountPercent":10, 
     "type":"offer", 
     "itemImagePath":"offers/offer_1506408444171.jpeg", 
     "unlimitedQuantity":true 
     } 
    ] 
} 

これは私がpojoクラスを作る必要がありandroidgsonを使用して作りたいjsonギあるとgsonライブラリーで、このようなJSON構造を作成したいが、私は同じことを生成できませんでしたギ あなたはすでに、すべての部品を行わは、私は、適切なオブジェクトの作成

[ 
    { 
     "contactNumber":"8149425758", 
     "couponcode":{ 
     "midval":0, 
     "type":"percent" 
     }, 
     "discount":0, 
     "email":"[email protected]", 
     "firstName":"Bharat", 
     "lastName":"Udasi", 
     "orderLines":[ 
     { 
      "actualPrice":50, 
      "dealPrice":45, 
      "discountPercent":0, 
      "endValidity":"1970-01-01T17:30:00.000Z", 
      "itemImagePath":"https://s3.amazonaws.com/bigzpoon-develop/offers/offer_1509619452389.png", 
      "itemName":"Panir Tikka", 
      "netAmount":45, 
      "offerId":"6d16df4a-ab9c-4930-8337-2b3f65969fb8", 
      "quantity":3, 
      "startValidity":"1970-01-01T01:30:00.000Z", 
      "type":"offer", 
      "unlimitedQuantity":false 
     }, 
     { 
      "actualPrice":50, 
      "dealPrice":45, 
      "discountPercent":0, 
      "endValidity":"1970-01-01T17:30:00.000Z", 
      "itemImagePath":"https://s3.amazonaws.com/bigzpoon-develop/offers/offer_1509609642206.png", 
      "itemName":"Panir Tikka", 
      "netAmount":45, 
      "offerId":"d4152ba9-a5bc-4f5b-ad03-a5180a0e0199", 
      "quantity":11, 
      "startValidity":"1970-01-01T01:30:00.000Z", 
      "type":"offer", 
      "unlimitedQuantity":true 
     }, 
     { 
      "actualPrice":80, 
      "dealPrice":80, 
      "discountPercent":0, 
      "endValidity":"1970-01-01T17:30:00.000Z", 
      "itemImagePath":"menu/Burger_1507295095917.jpeg", 
      "itemName":"Burger", 
      "menuId":"5ea97c74-74fe-4e96-beb6-ba7772a160e3", 
      "netAmount":80, 
      "quantity":11, 
      "startValidity":"1970-01-01T17:30:00.000Z", 
      "type":"menu", 
      "unlimitedQuantity":true 
     }, 
     { 
      "actualPrice":50, 
      "dealPrice":50, 
      "discountPercent":0, 
      "endValidity":"1970-01-01T17:30:00.000Z", 
      "itemImagePath":"menu/Panir-Tikka_1507295128370.jpeg", 
      "itemName":"Panir Tikka", 
      "menuId":"70b4d4d3-2679-4e16-a90c-b081401c268f", 
      "netAmount":50, 
      "quantity":9, 
      "startValidity":"1970-01-01T17:30:00.000Z", 
      "type":"menu", 
      "unlimitedQuantity":true 
     } 
     ], 
     "orderNetAmount":"24.0", 
     "orderQuantity":34, 
     "payerId":"60g59yxg", 
     "paymentMode":"paypal_account", 
     "paymentRefKey":"60g59yxg", 
     "paymentStatus":"1000", 
     "paypalPaymentId":"60g59yxg", 
     "restaurantId":"9b104614-b02f-45aa-ab6e-a2afd569835a", 
     "restaurantName":"Michel Plaza", 
     "salesTax":0, 
     "serviceFee":156.8, 
     "subTotal":1960, 
     "transactionStatus":"settling", 
     "userId":"538eb196-3f6a-415e-bd13-ffc4191c37b1" 
    }, 
    { 
     "contactNumber":"8149425758", 
     "couponcode":{ 
     "midval":0, 
     "type":"percent" 
     }, 
     "discount":0, 
     "email":"[email protected]", 
     "firstName":"Bharat", 
     "lastName":"Udasi", 
     "orderLines":[ 
     { 
      "actualPrice":50, 
      "dealPrice":45, 
      "discountPercent":0, 
      "endValidity":"1970-01-01T17:30:00.000Z", 
      "itemImagePath":"https://s3.amazonaws.com/bigzpoon-develop/offers/offer_1509619452389.png", 
      "itemName":"Panir Tikka", 
      "netAmount":45, 
      "offerId":"6d16df4a-ab9c-4930-8337-2b3f65969fb8", 
      "quantity":3, 
      "startValidity":"1970-01-01T01:30:00.000Z", 
      "type":"offer", 
      "unlimitedQuantity":false 
     }, 
     { 
      "actualPrice":50, 
      "dealPrice":45, 
      "discountPercent":0, 
      "endValidity":"1970-01-01T17:30:00.000Z", 
      "itemImagePath":"https://s3.amazonaws.com/bigzpoon-develop/offers/offer_1509609642206.png", 
      "itemName":"Panir Tikka", 
      "netAmount":45, 
      "offerId":"d4152ba9-a5bc-4f5b-ad03-a5180a0e0199", 
      "quantity":11, 
      "startValidity":"1970-01-01T01:30:00.000Z", 
      "type":"offer", 
      "unlimitedQuantity":true 
     }, 
     { 
      "actualPrice":80, 
      "dealPrice":80, 
      "discountPercent":0, 
      "endValidity":"1970-01-01T17:30:00.000Z", 
      "itemImagePath":"menu/Burger_1507295095917.jpeg", 
      "itemName":"Burger", 
      "menuId":"5ea97c74-74fe-4e96-beb6-ba7772a160e3", 
      "netAmount":80, 
      "quantity":11, 
      "startValidity":"1970-01-01T17:30:00.000Z", 
      "type":"menu", 
      "unlimitedQuantity":true 
     }, 
     { 
      "actualPrice":50, 
      "dealPrice":50, 
      "discountPercent":0, 
      "endValidity":"1970-01-01T17:30:00.000Z", 
      "itemImagePath":"menu/Panir-Tikka_1507295128370.jpeg", 
      "itemName":"Panir Tikka", 
      "menuId":"70b4d4d3-2679-4e16-a90c-b081401c268f", 
      "netAmount":50, 
      "quantity":9, 
      "startValidity":"1970-01-01T17:30:00.000Z", 
      "type":"menu", 
      "unlimitedQuantity":true 
     } 
     ], 
     "orderNetAmount":"24.0", 
     "orderQuantity":34, 
     "payerId":"60g59yxg", 
     "paymentMode":"paypal_account", 
     "paymentRefKey":"60g59yxg", 
     "paymentStatus":"1000", 
     "paypalPaymentId":"60g59yxg", 
     "restaurantId":"9b104614-b02f-45aa-ab6e-a2afd569835a", 
     "restaurantName":"Michel Plaza", 
     "salesTax":0, 
     "serviceFee":156.8, 
     "subTotal":1960, 
     "transactionStatus":"settling", 
     "userId":"538eb196-3f6a-415e-bd13-ffc4191c37b1" 
    }, 
    { 
     "contactNumber":"8149425758", 
     "couponcode":{ 
     "midval":0, 
     "type":"percent" 
     }, 
     "discount":0, 
     "email":"[email protected]", 
     "firstName":"Bharat", 
     "lastName":"Udasi", 
     "orderLines":[ 
     { 
      "actualPrice":50, 
      "dealPrice":45, 
      "discountPercent":0, 
      "endValidity":"1970-01-01T17:30:00.000Z", 
      "itemImagePath":"https://s3.amazonaws.com/bigzpoon-develop/offers/offer_1509619452389.png", 
      "itemName":"Panir Tikka", 
      "netAmount":45, 
      "offerId":"6d16df4a-ab9c-4930-8337-2b3f65969fb8", 
      "quantity":3, 
      "startValidity":"1970-01-01T01:30:00.000Z", 
      "type":"offer", 
      "unlimitedQuantity":false 
     }, 
     { 
      "actualPrice":50, 
      "dealPrice":45, 
      "discountPercent":0, 
      "endValidity":"1970-01-01T17:30:00.000Z", 
      "itemImagePath":"https://s3.amazonaws.com/bigzpoon-develop/offers/offer_1509609642206.png", 
      "itemName":"Panir Tikka", 
      "netAmount":45, 
      "offerId":"d4152ba9-a5bc-4f5b-ad03-a5180a0e0199", 
      "quantity":11, 
      "startValidity":"1970-01-01T01:30:00.000Z", 
      "type":"offer", 
      "unlimitedQuantity":true 
     }, 
     { 
      "actualPrice":80, 
      "dealPrice":80, 
      "discountPercent":0, 
      "endValidity":"1970-01-01T17:30:00.000Z", 
      "itemImagePath":"menu/Burger_1507295095917.jpeg", 
      "itemName":"Burger", 
      "menuId":"5ea97c74-74fe-4e96-beb6-ba7772a160e3", 
      "netAmount":80, 
      "quantity":11, 
      "startValidity":"1970-01-01T17:30:00.000Z", 
      "type":"menu", 
      "unlimitedQuantity":true 
     }, 
     { 
      "actualPrice":50, 
      "dealPrice":50, 
      "discountPercent":0, 
      "endValidity":"1970-01-01T17:30:00.000Z", 
      "itemImagePath":"menu/Panir-Tikka_1507295128370.jpeg", 
      "itemName":"Panir Tikka", 
      "menuId":"70b4d4d3-2679-4e16-a90c-b081401c268f", 
      "netAmount":50, 
      "quantity":9, 
      "startValidity":"1970-01-01T17:30:00.000Z", 
      "type":"menu", 
      "unlimitedQuantity":true 
     } 
     ], 
     "orderNetAmount":"24.0", 
     "orderQuantity":34, 
     "payerId":"60g59yxg", 
     "paymentMode":"paypal_account", 
     "paymentRefKey":"60g59yxg", 
     "paymentStatus":"1000", 
     "paypalPaymentId":"60g59yxg", 
     "restaurantId":"9b104614-b02f-45aa-ab6e-a2afd569835a", 
     "restaurantName":"Michel Plaza", 
     "salesTax":0, 
     "serviceFee":156.8, 
     "subTotal":1960, 
     "transactionStatus":"settling", 
     "userId":"538eb196-3f6a-415e-bd13-ffc4191c37b1" 
    }, 
    { 
     "contactNumber":"8149425758", 
     "couponcode":{ 
     "midval":0, 
     "type":"percent" 
     }, 
     "discount":0, 
     "email":"[email protected]", 
     "firstName":"Bharat", 
     "lastName":"Udasi", 
     "orderLines":[ 
     { 
      "actualPrice":50, 
      "dealPrice":45, 
      "discountPercent":0, 
      "endValidity":"1970-01-01T17:30:00.000Z", 
      "itemImagePath":"https://s3.amazonaws.com/bigzpoon-develop/offers/offer_1509619452389.png", 
      "itemName":"Panir Tikka", 
      "netAmount":45, 
      "offerId":"6d16df4a-ab9c-4930-8337-2b3f65969fb8", 
      "quantity":3, 
      "startValidity":"1970-01-01T01:30:00.000Z", 
      "type":"offer", 
      "unlimitedQuantity":false 
     }, 
     { 
      "actualPrice":50, 
      "dealPrice":45, 
      "discountPercent":0, 
      "endValidity":"1970-01-01T17:30:00.000Z", 
      "itemImagePath":"https://s3.amazonaws.com/bigzpoon-develop/offers/offer_1509609642206.png", 
      "itemName":"Panir Tikka", 
      "netAmount":45, 
      "offerId":"d4152ba9-a5bc-4f5b-ad03-a5180a0e0199", 
      "quantity":11, 
      "startValidity":"1970-01-01T01:30:00.000Z", 
      "type":"offer", 
      "unlimitedQuantity":true 
     }, 
     { 
      "actualPrice":80, 
      "dealPrice":80, 
      "discountPercent":0, 
      "endValidity":"1970-01-01T17:30:00.000Z", 
      "itemImagePath":"menu/Burger_1507295095917.jpeg", 
      "itemName":"Burger", 
      "menuId":"5ea97c74-74fe-4e96-beb6-ba7772a160e3", 
      "netAmount":80, 
      "quantity":11, 
      "startValidity":"1970-01-01T17:30:00.000Z", 
      "type":"menu", 
      "unlimitedQuantity":true 
     }, 
     { 
      "actualPrice":50, 
      "`enter code here`dealPrice":50, 
      "discountPercent":0, 
      "endValidity":"1970-01-01T17:30:00.000Z", 
      "itemImagePath":"menu/Panir-Tikka_1507295128370.jpeg", 
      "itemName":"Panir Tikka", 
      "menuId":"70b4d4d3-2679-4e16-a90c-b081401c268f", 
      "netAmount":50, 
      "quantity":9, 
      "startValidity":"1970-01-01T17:30:00.000Z", 
      "type":"menu", 
      "unlimitedQuantity":true 
     } 
     ], 
     "orderNetAmount":"24.0", 
     "orderQuantity":34, 
     "payerId":"60g59yxg", 
     "paymentMode":"paypal_account", 
     "paymentRefKey":"60g59yxg", 
     "paymentStatus":"1000", 
     "paypalPaymentId":"60g59yxg", 
     "restaurantId":"9b104614-b02f-45aa-ab6e-a2afd569835a", 
     "restaurantName":"Michel Plaza", 
     "salesTax":0, 
     "serviceFee":156.8, 
     "subTotal":1960, 
     "transactionStatus":"settling", 
     "userId":"538eb196-3f6a-415e-bd13-ffc4191c37b1" 
    } 
]  
+0

実際の結果が間違っているのを見ることはできません。何が間違っているのか説明できますか? –

+0

私はオブジェクト形式の結果が配列形式で来る必要があることを意味するのは、jsonが[私は{で始める必要がある。それのために私は助けを必要とする –

答えて

0

以下のように私はgsonを使用してギを生成します。あなたがする必要がある最後のことは、gsonの文字列をJSONArrayに変換します。あなたが好きではない。この

{ 
    "restaurantId":"0a60fa5e-642c-4e4f-ae37-a7c8093e1659", 
     ' 
     ' 
     ' 
     ' 
     ' 
    "contactNumber":"9516238470", 
    "couponcode":{ 
     ' 
     ' 
     ' 
     ' 
    }, 
    "orderLines":[ 
     ' 
     ' 
     ' 
     ' 
    ] 
} 

のような必要がある場合は、その

JSONArray jsonarray = new JSONArray("gson string"); 

ために、このコードを使用し、この

{ 
    "contactNumber":"8149425758", 
     ' 
     ' 
     ' 
     ' 
     ' 
    "couponcode":{ 
     ' 
     ' 
     ' 
     ' 
    }, 
    "lastName":"Udasi", 
    "orderLines":[ 
     ' 
     ' 
     ' 
     ' 
    ], 
    "orderNetAmount":"24.0", 
     ' 
     ' 
     ' 
} 

データは、要素のキーでソートするので、これが起こります。要素キーを見ればわかります

+0

それは私の問題を解決するありがとう –

関連する問題