Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 迭代JSONObject并获取其更深层次的child子值_Java_Android_Arrays_Json - Fatal编程技术网

Java 迭代JSONObject并获取其更深层次的child子值

Java 迭代JSONObject并获取其更深层次的child子值,java,android,arrays,json,Java,Android,Arrays,Json,我从API调用中得到以下JsonObject作为响应- { "$type": "VerteSearch.Core.Models.SearchResultCollection`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core", "count": 74, "data": [ { "$type": "VerteSearch.Core.

我从API调用中得到以下JsonObject作为响应-

{
  "$type": "VerteSearch.Core.Models.SearchResultCollection`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core",
  "count": 74,
  "data": [
    {
      "$type": "VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core",
      "score": 1.41421354,
      "resultData": {
        "$type": "VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core",
        "id": "1",
        "vendorId": 1,
        "vendorPrefix": "VS0007",
        "vendorName": "kiko+ & gg*",
        "shortDescription": "High Quality modern-minimalist wooden toys. Designed in Japan.",
        "imageUrl": "https://images.myverte.com/default-image_143.png",
        "imageId": 0,
        "displayOrder": 1,
        "seName": "kikoandgg",
        "url": "https://myverte.com/kikoandgg",
        "logoPicture": "https://images.myverte.com/0141614_270.png",
        "logoPictureId": 141614,
        "backgroundPicture": "https://images.myverte.com/0141612_270.png",
        "backgroundPictureId": 141612,
        "frontPicture": "https://images.myverte.com/0141609_270.png",
        "frontPictureId": 141609,
        "bannerPicture": null,
        "bannerPictureId": 0,
        "priceMin": 0.0,
        "priceMax": 138.0,
        "categoriesNames": "Toys",
        "maxFavoritesCount": 2
      }
    },
    {
      "$type": "VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core",
      "score": 1.41421354,
      "resultData": {
        "$type": "VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core",
        "id": "3",
        "vendorId": 3,
        "vendorPrefix": "VS0008",
        "vendorName": "Luna Rose",
        "shortDescription": "Jewelry & Accessories Made From 99% Recycled Silver.",
        "imageUrl": "https://images.myverte.com/default-image_143.png",
        "imageId": 0,
        "displayOrder": 1,
        "seName": "luna-rose",
        "url": "https://myverte.com/luna-rose",
        "logoPicture": "https://images.myverte.com/0129803_270.png",
        "logoPictureId": 129803,
        "backgroundPicture": "https://images.myverte.com/0129802_270.png",
        "backgroundPictureId": 129802,
        "frontPicture": "https://images.myverte.com/0129801_270.png",
        "frontPictureId": 129801,
        "bannerPicture": null,
        "bannerPictureId": 0,
        "priceMin": 129.0,
        "priceMax": 189.0,
        "categoriesNames": "Jewelry",
        "maxFavoritesCount": 5
      }
    },
    {
      "$type": "VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core",
      "score": 1.41421354,
      "resultData": {
        "$type": "VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core",
        "id": "4",
        "vendorId": 4,
        "vendorPrefix": "VS0009",
        "vendorName": "Lumi Charge",
        "shortDescription": "The Ultimate LED Desk Lamp Charging Station",
        "imageUrl": "https://images.myverte.com/default-image_143.png",
        "imageId": 0,
        "displayOrder": 1,
        "seName": "lumi-charge",
        "url": "https://myverte.com/lumi-charge",
        "logoPicture": "https://images.myverte.com/0093139_LumiLogo_270.png",
        "logoPictureId": 93139,
        "backgroundPicture": "https://images.myverte.com/0093137_BackgroundImage-Lumicharge_270.png",
        "backgroundPictureId": 93137,
        "frontPicture": "https://images.myverte.com/0093138_LumiFront1_270.png",
        "frontPictureId": 93138,
        "bannerPicture": null,
        "bannerPictureId": 0,
        "priceMin": 0.0,
        "priceMax": 0.0,
        "categoriesNames": "Electronics",
        "maxFavoritesCount": 0
      }
    },
    {
      "$type": "VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core",
      "score": 1.41421354,
      "resultData": {
        "$type": "VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core",
        "id": "5",
        "vendorId": 5,
        "vendorPrefix": "VS0010",
        "vendorName": "Milton&Goose",
        "shortDescription": "Wooden Play Kitchens Made In The USA.",
        "imageUrl": "https://images.myverte.com/default-image_143.png",
        "imageId": 0,
        "displayOrder": 1,
        "seName": "miltongoose",
        "url": "https://myverte.com/miltongoose",
        "logoPicture": "https://images.myverte.com/0002009_270.png",
        "logoPictureId": 2009,
        "backgroundPicture": "https://images.myverte.com/0002007_270.png",
        "backgroundPictureId": 2007,
        "frontPicture": "https://images.myverte.com/0002008_270.png",
        "frontPictureId": 2008,
        "bannerPicture": null,
        "bannerPictureId": 0,
        "priceMin": 649.0,
        "priceMax": 799.0,
        "categoriesNames": "Toys",
        "maxFavoritesCount": 0
      }
    },
    {
      "$type": "VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core",
      "score": 1.41421354,
      "resultData": {
        "$type": "VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core",
        "id": "7",
        "vendorId": 7,
        "vendorPrefix": "VS0012",
        "vendorName": "Birthstone Scents",
        "shortDescription": "Perfumes and Home Fragrances Inspired by Gemstones.",
        "imageUrl": "https://images.myverte.com/default-image_143.png",
        "imageId": 0,
        "displayOrder": 1,
        "seName": "birthstone-scents",
        "url": "https://myverte.com/birthstone-scents",
        "logoPicture": "https://images.myverte.com/0002257_270.png",
        "logoPictureId": 2257,
        "backgroundPicture": "https://images.myverte.com/0003156_270.jpeg",
        "backgroundPictureId": 3156,
        "frontPicture": "https://images.myverte.com/0000641_270.png",
        "frontPictureId": 641,
        "bannerPicture": null,
        "bannerPictureId": 0,
        "priceMin": 45.0,
        "priceMax": 45.0,
        "categoriesNames": "Candles,Perfume Oil",
        "maxFavoritesCount": 8
      }
    },
    {
      "$type": "VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core",
      "score": 1.41421354,
      "resultData": {
        "$type": "VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core",
        "id": "8",
        "vendorId": 8,
        "vendorPrefix": "VS0013",
        "vendorName": "Rampley & Co",
        "shortDescription": "High Quality, Elegant Pocket Squares with Unique Designs.",
        "imageUrl": "https://images.myverte.com/default-image_143.png",
        "imageId": 0,
        "displayOrder": 1,
        "seName": "rampley-co",
        "url": "https://myverte.com/rampley-co",
        "logoPicture": "https://images.myverte.com/0129814_270.png",
        "logoPictureId": 129814,
        "backgroundPicture": "https://images.myverte.com/0129813_270.png",
        "backgroundPictureId": 129813,
        "frontPicture": "https://images.myverte.com/0129812_270.png",
        "frontPictureId": 129812,
        "bannerPicture": null,
        "bannerPictureId": 0,
        "priceMin": 79.0,
        "priceMax": 98.0,
        "categoriesNames": "Pocket Squares",
        "maxFavoritesCount": 1
      }
    },
    {
      "$type": "VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core",
      "score": 1.41421354,
      "resultData": {
        "$type": "VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core",
        "id": "9",
        "vendorId": 9,
        "vendorPrefix": "VS0014",
        "vendorName": "Unbound",
        "shortDescription": "A Sexual Wellness Company... for When You're Feeling Yourself...",
        "imageUrl": "https://images.myverte.com/default-image_143.png",
        "imageId": 0,
        "displayOrder": 1,
        "seName": "unbound",
        "url": "https://myverte.com/unbound",
        "logoPicture": "https://images.myverte.com/0102324_270.png",
        "logoPictureId": 102324,
        "backgroundPicture": "https://images.myverte.com/0102320_270.png",
        "backgroundPictureId": 102320,
        "frontPicture": "https://images.myverte.com/0102314_270.png",
        "frontPictureId": 102314,
        "bannerPicture": null,
        "bannerPictureId": 0,
        "priceMin": 16.0,
        "priceMax": 99.0,
        "categoriesNames": "Vibrator,Jewelry,Lubricant,Accessories",
        "maxFavoritesCount": 2
      }
    },
    {
      "$type": "VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core",
      "score": 1.41421354,
      "resultData": {
        "$type": "VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core",
        "id": "10",
        "vendorId": 10,
        "vendorPrefix": "VS0015",
        "vendorName": "Stryx",
        "shortDescription": "Rethinking the Meaning of Men's “Cosmetics” Products.",
        "imageUrl": "https://images.myverte.com/default-image_143.png",
        "imageId": 0,
        "displayOrder": 1,
        "seName": "stryx",
        "url": "https://myverte.com/stryx",
        "logoPicture": "https://images.myverte.com/0140678_270.png",
        "logoPictureId": 140678,
        "backgroundPicture": "https://images.myverte.com/0140677_270.png",
        "backgroundPictureId": 140677,
        "frontPicture": "https://images.myverte.com/0140676_270.png",
        "frontPictureId": 140676,
        "bannerPicture": null,
        "bannerPictureId": 0,
        "priceMin": 29.0,
        "priceMax": 29.0,
        "categoriesNames": "Cosmetics",
        "maxFavoritesCount": 5
      }
    },
    {
      "$type": "VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core",
      "score": 1.41421354,
      "resultData": {
        "$type": "VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core",
        "id": "11",
        "vendorId": 11,
        "vendorPrefix": "VS0016",
        "vendorName": "Temporary Forevers",
        "shortDescription": "Goods Created for Your Daily Journey. Crafted to Last.",
        "imageUrl": "https://images.myverte.com/default-image_143.png",
        "imageId": 0,
        "displayOrder": 1,
        "seName": "temporary-forevers",
        "url": "https://myverte.com/temporary-forevers",
        "logoPicture": "https://images.myverte.com/0130521_270.png",
        "logoPictureId": 130521,
        "backgroundPicture": "https://images.myverte.com/0130520_270.png",
        "backgroundPictureId": 130520,
        "frontPicture": "https://images.myverte.com/0130519_270.png",
        "frontPictureId": 130519,
        "bannerPicture": null,
        "bannerPictureId": 0,
        "priceMin": 305.0,
        "priceMax": 395.0,
        "categoriesNames": "Accessories",
        "maxFavoritesCount": 11
      }
    }
  ]
}
问题是,我只需要这个JsonObject的一部分,更深层次的子对象

我需要的基本上是来自resultData变量的信息—vendorId、vendorName、shortDescription、imageURL、vendorURL

resultData是一个JSONObject数组,因此我需要遍历它们并列出我自己的对象

这样做的方法是什么

编辑-

尝试了以下解决方案-

私有void GetVendorListJSonObject主体{ JsonArray dataArray=body.getAsJsonArraydata; Gson Gson=新Gson; JSONArray JSONArray=gson.fromJsondataArray,JSONArray.class; List vendorModelList=新建ArrayList; 对于int i=0;i java.lang.IllegalStateException:应为BEGIN_对象,但在路径处为BEGIN_数组$


我错过了什么?数据实际上是一个数组而不是对象

使用gson的完整解决方案:

public class SOActivity extends AppCompatActivity {

String TAG = "StackOverflow";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_so);

    String jsonStr = "{\"$type\":\"VerteSearch.Core.Models.SearchResultCollection`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core\",\"count\":74,\"data\":[{\"$type\":\"VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core\",\"score\":1.41421354,\"resultData\":{\"$type\":\"VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core\",\"id\":\"1\",\"vendorId\":1,\"vendorPrefix\":\"VS0007\",\"vendorName\":\"kiko+ & gg*\",\"shortDescription\":\"High Quality modern-minimalist wooden toys. Designed in Japan.\",\"imageUrl\":\"https://images.myverte.com/default-image_143.png\",\"imageId\":0,\"displayOrder\":1,\"seName\":\"kikoandgg\",\"url\":\"https://myverte.com/kikoandgg\",\"logoPicture\":\"https://images.myverte.com/0141614_270.png\",\"logoPictureId\":141614,\"backgroundPicture\":\"https://images.myverte.com/0141612_270.png\",\"backgroundPictureId\":141612,\"frontPicture\":\"https://images.myverte.com/0141609_270.png\",\"frontPictureId\":141609,\"bannerPicture\":null,\"bannerPictureId\":0,\"priceMin\":0,\"priceMax\":138,\"categoriesNames\":\"Toys\",\"maxFavoritesCount\":2}},{\"$type\":\"VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core\",\"score\":1.41421354,\"resultData\":{\"$type\":\"VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core\",\"id\":\"3\",\"vendorId\":3,\"vendorPrefix\":\"VS0008\",\"vendorName\":\"Luna Rose\",\"shortDescription\":\"Jewelry & Accessories Made From 99% Recycled Silver.\",\"imageUrl\":\"https://images.myverte.com/default-image_143.png\",\"imageId\":0,\"displayOrder\":1,\"seName\":\"luna-rose\",\"url\":\"https://myverte.com/luna-rose\",\"logoPicture\":\"https://images.myverte.com/0129803_270.png\",\"logoPictureId\":129803,\"backgroundPicture\":\"https://images.myverte.com/0129802_270.png\",\"backgroundPictureId\":129802,\"frontPicture\":\"https://images.myverte.com/0129801_270.png\",\"frontPictureId\":129801,\"bannerPicture\":null,\"bannerPictureId\":0,\"priceMin\":129,\"priceMax\":189,\"categoriesNames\":\"Jewelry\",\"maxFavoritesCount\":5}},{\"$type\":\"VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core\",\"score\":1.41421354,\"resultData\":{\"$type\":\"VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core\",\"id\":\"4\",\"vendorId\":4,\"vendorPrefix\":\"VS0009\",\"vendorName\":\"Lumi Charge\",\"shortDescription\":\"The Ultimate LED Desk Lamp Charging Station\",\"imageUrl\":\"https://images.myverte.com/default-image_143.png\",\"imageId\":0,\"displayOrder\":1,\"seName\":\"lumi-charge\",\"url\":\"https://myverte.com/lumi-charge\",\"logoPicture\":\"https://images.myverte.com/0093139_LumiLogo_270.png\",\"logoPictureId\":93139,\"backgroundPicture\":\"https://images.myverte.com/0093137_BackgroundImage-Lumicharge_270.png\",\"backgroundPictureId\":93137,\"frontPicture\":\"https://images.myverte.com/0093138_LumiFront1_270.png\",\"frontPictureId\":93138,\"bannerPicture\":null,\"bannerPictureId\":0,\"priceMin\":0,\"priceMax\":0,\"categoriesNames\":\"Electronics\",\"maxFavoritesCount\":0}},{\"$type\":\"VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core\",\"score\":1.41421354,\"resultData\":{\"$type\":\"VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core\",\"id\":\"5\",\"vendorId\":5,\"vendorPrefix\":\"VS0010\",\"vendorName\":\"Milton&Goose\",\"shortDescription\":\"Wooden Play Kitchens Made In The USA.\",\"imageUrl\":\"https://images.myverte.com/default-image_143.png\",\"imageId\":0,\"displayOrder\":1,\"seName\":\"miltongoose\",\"url\":\"https://myverte.com/miltongoose\",\"logoPicture\":\"https://images.myverte.com/0002009_270.png\",\"logoPictureId\":2009,\"backgroundPicture\":\"https://images.myverte.com/0002007_270.png\",\"backgroundPictureId\":2007,\"frontPicture\":\"https://images.myverte.com/0002008_270.png\",\"frontPictureId\":2008,\"bannerPicture\":null,\"bannerPictureId\":0,\"priceMin\":649,\"priceMax\":799,\"categoriesNames\":\"Toys\",\"maxFavoritesCount\":0}},{\"$type\":\"VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core\",\"score\":1.41421354,\"resultData\":{\"$type\":\"VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core\",\"id\":\"7\",\"vendorId\":7,\"vendorPrefix\":\"VS0012\",\"vendorName\":\"Birthstone Scents\",\"shortDescription\":\"Perfumes and Home Fragrances Inspired by Gemstones.\",\"imageUrl\":\"https://images.myverte.com/default-image_143.png\",\"imageId\":0,\"displayOrder\":1,\"seName\":\"birthstone-scents\",\"url\":\"https://myverte.com/birthstone-scents\",\"logoPicture\":\"https://images.myverte.com/0002257_270.png\",\"logoPictureId\":2257,\"backgroundPicture\":\"https://images.myverte.com/0003156_270.jpeg\",\"backgroundPictureId\":3156,\"frontPicture\":\"https://images.myverte.com/0000641_270.png\",\"frontPictureId\":641,\"bannerPicture\":null,\"bannerPictureId\":0,\"priceMin\":45,\"priceMax\":45,\"categoriesNames\":\"Candles,Perfume Oil\",\"maxFavoritesCount\":8}},{\"$type\":\"VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core\",\"score\":1.41421354,\"resultData\":{\"$type\":\"VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core\",\"id\":\"8\",\"vendorId\":8,\"vendorPrefix\":\"VS0013\",\"vendorName\":\"Rampley & Co\",\"shortDescription\":\"High Quality, Elegant Pocket Squares with Unique Designs.\",\"imageUrl\":\"https://images.myverte.com/default-image_143.png\",\"imageId\":0,\"displayOrder\":1,\"seName\":\"rampley-co\",\"url\":\"https://myverte.com/rampley-co\",\"logoPicture\":\"https://images.myverte.com/0129814_270.png\",\"logoPictureId\":129814,\"backgroundPicture\":\"https://images.myverte.com/0129813_270.png\",\"backgroundPictureId\":129813,\"frontPicture\":\"https://images.myverte.com/0129812_270.png\",\"frontPictureId\":129812,\"bannerPicture\":null,\"bannerPictureId\":0,\"priceMin\":79,\"priceMax\":98,\"categoriesNames\":\"Pocket Squares\",\"maxFavoritesCount\":1}},{\"$type\":\"VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core\",\"score\":1.41421354,\"resultData\":{\"$type\":\"VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core\",\"id\":\"9\",\"vendorId\":9,\"vendorPrefix\":\"VS0014\",\"vendorName\":\"Unbound\",\"shortDescription\":\"A Sexual Wellness Company... for When You're Feeling Yourself...\",\"imageUrl\":\"https://images.myverte.com/default-image_143.png\",\"imageId\":0,\"displayOrder\":1,\"seName\":\"unbound\",\"url\":\"https://myverte.com/unbound\",\"logoPicture\":\"https://images.myverte.com/0102324_270.png\",\"logoPictureId\":102324,\"backgroundPicture\":\"https://images.myverte.com/0102320_270.png\",\"backgroundPictureId\":102320,\"frontPicture\":\"https://images.myverte.com/0102314_270.png\",\"frontPictureId\":102314,\"bannerPicture\":null,\"bannerPictureId\":0,\"priceMin\":16,\"priceMax\":99,\"categoriesNames\":\"Vibrator,Jewelry,Lubricant,Accessories\",\"maxFavoritesCount\":2}},{\"$type\":\"VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core\",\"score\":1.41421354,\"resultData\":{\"$type\":\"VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core\",\"id\":\"10\",\"vendorId\":10,\"vendorPrefix\":\"VS0015\",\"vendorName\":\"Stryx\",\"shortDescription\":\"Rethinking the Meaning of Men's “Cosmetics” Products.\",\"imageUrl\":\"https://images.myverte.com/default-image_143.png\",\"imageId\":0,\"displayOrder\":1,\"seName\":\"stryx\",\"url\":\"https://myverte.com/stryx\",\"logoPicture\":\"https://images.myverte.com/0140678_270.png\",\"logoPictureId\":140678,\"backgroundPicture\":\"https://images.myverte.com/0140677_270.png\",\"backgroundPictureId\":140677,\"frontPicture\":\"https://images.myverte.com/0140676_270.png\",\"frontPictureId\":140676,\"bannerPicture\":null,\"bannerPictureId\":0,\"priceMin\":29,\"priceMax\":29,\"categoriesNames\":\"Cosmetics\",\"maxFavoritesCount\":5}},{\"$type\":\"VerteSearch.Core.Models.SearchResult`1[[VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core]], VerteSearch.Core\",\"score\":1.41421354,\"resultData\":{\"$type\":\"VerteSearch.Core.Models.IndexEntities.IndexedVendor, VerteSearch.Core\",\"id\":\"11\",\"vendorId\":11,\"vendorPrefix\":\"VS0016\",\"vendorName\":\"Temporary Forevers\",\"shortDescription\":\"Goods Created for Your Daily Journey. Crafted to Last.\",\"imageUrl\":\"https://images.myverte.com/default-image_143.png\",\"imageId\":0,\"displayOrder\":1,\"seName\":\"temporary-forevers\",\"url\":\"https://myverte.com/temporary-forevers\",\"logoPicture\":\"https://images.myverte.com/0130521_270.png\",\"logoPictureId\":130521,\"backgroundPicture\":\"https://images.myverte.com/0130520_270.png\",\"backgroundPictureId\":130520,\"frontPicture\":\"https://images.myverte.com/0130519_270.png\",\"frontPictureId\":130519,\"bannerPicture\":null,\"bannerPictureId\":0,\"priceMin\":305,\"priceMax\":395,\"categoriesNames\":\"Accessories\",\"maxFavoritesCount\":11}}]}";
    Gson gson = new GsonBuilder().create();
    ResponseWrappper response =  gson.fromJson(jsonStr,ResponseWrappper.class);

    for(DataWrapper dataWrapper: response.data){
        Log.i(TAG,dataWrapper.resultData.toString());
    }
}



class ResponseWrappper {
    @SerializedName("data")
    public List<DataWrapper> data;
}

class DataWrapper {
    @SerializedName("resultData")
    VendorModel resultData;
}

class VendorModel {

    @SerializedName("id")
    public int id;

    @SerializedName("vendorName")
    public String name;

    @SerializedName("shortDescription")
    public String shortDescription;

    @SerializedName("imageUrl")
    public String imageURL;

    @SerializedName("url")
    public String url;

    public VendorModel(int id, String name, String shortDescription, String imageURL, String url) {
        this.id = id;
        this.name = name;
        this.shortDescription = shortDescription;
        this.imageURL = imageURL;
        this.url = url;
    }

    @Override
    public String toString() {
        return "Vendor{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", shortDescription='" + shortDescription + '\'' +
                ", imageURL='" + imageURL + '\'' +
                ", url='" + url + '\'' +
                '}';
    }
}
}

遍历resultData并解析

private void getVendorsList(JsonObject body) {
    JsonArray jsonArray = body.getAsJsonArray("data");
    List<VendorModel> vendorModelList = new ArrayList<>();
    if(jsonArray != null) {
        for (int i = 0; i < jsonArray.size(); i++) {
            JsonObject dataObject = jsonArray.get(i).getAsJsonObject();
            if(dataObject != null) {
                JsonObject resultObject = dataObject.getAsJsonObject("resultData");
                if(resultObject != null) {

                    //Manual parse
                    int id = resultObject.get("id").getAsInt();
                    String vendorName = resultObject.get("vendorName").getAsString();
                    String shortDescription = resultObject.get("shortDescription").getAsString();
                    String imageUrl = resultObject.get("imageUrl").getAsString();
                    String url = resultObject.get("url").getAsString();

                    VendorModel vendorModel = new VendorModel(id,vendorName, shortDescription, imageUrl, url);
                    vendorModelList.add(vendorModel);

                    //Parse using Gson. Also try this instead of above if your json key and model property are aligned
                    /*VendorModel vendorModel = new Gson().fromJson(resultObject, VendorModel.class);
                    vendorModelList.add(vendorModel);*/
                }
            }
        }
    }

    Log.d("vendorsList", String.valueOf(vendorModelList));
}

注意:您在实现中混合了org.json和google.gson

您应该试试这段代码

private void getVendorsList(JSONObject body) {

    try {
        JSONArray dataArray = body.getJSONArray("data");

        List<VendorModel> vendorModelList = new ArrayList<>();

        for (int i = 0; i < dataArray.length(); i++) {
            try {
                JSONObject resultData = dataArray.getJSONObject(i).getJSONObject("resultData");
                int id = resultData.getInt("id");
                String vendorName = resultData.getString("vendorName");
                String shortDescription = resultData.getString("shortDescription");
                String imageUrl = resultData.getString("imageUrl");
                String url = resultData.getString("url");
                VendorModel vendorModel = new VendorModel(id, vendorName, shortDescription, imageUrl, url);
                vendorModelList.add(vendorModel);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

请参阅使用gson库进行序列化或反序列化请参阅更新post@AlonShlider我查过了,你能试一下上面的答案吗?我已经测试过了,我已经尝试过你的解决方案,问题是我从Gson库得到了JsonArray,而不是从Java库得到了JsonArray数组。如何将一个对象强制转换为另一个对象?当尝试从gson.fromJson强制转换它时,我得到了一个错误-预期的BEGIN_对象,但在路径$@AlonSlider处是BEGIN_数组。请查看JsonObject的更新解决方案,而不是JSONObject@AlonShlider,检查我的最新答案。希望会works@AlonShlider这不是你的解决方案吗?