Android json解析与Retrofit库

时间:2017-04-14 14:29:00

标签: android json rest asp.net-web-api retrofit2

我找到了以下json格式文件。是否可以通过改造进行解析?通常json具有每个部分的键和值,但是这里一个数组具有键,而其他数组具有值。那怎么解析呢?

{
  "insertnewdatas": {
    "columns": [
      "id",
      "operatorName",
      "latitude",
      "longitude",
      "location",
      "address",
      "currencies",
      "exchange",
      "exchangeLimits",
      "workingDays",
      "link",
      "phone",
      "email",
      "dateTime",
      "created_at",
      "updated_at"
    ],
    "records": [
      [
        3,
        "Coin Source",
        "22.3475",
        "91.8123",
        "Chittagong",
        "Oxygen , Chittagong",
        "Cash",
        "option2",
        "$500/month",
        "30",
        "no link",
        "017000000000",
        "arifhasnat.info@gmail.com",
        "21-10-2017",
        "2017-03-01 17:40:42",
        "2017-03-01 17:40:42"
      ],
      [
        4,
        "Coin Source",
        "22.3475",
        "91.8123",
        "Chittagong",
        "Oxygen , Chittagong",
        "Cash",
        "option2",
        "$500/month",
        "30",
        "no link",
        "017000000000",
        "arifhasnat.info@gmail.com",
        "21-10-2017",
        "2017-03-01 17:40:49",
        "2017-03-01 17:40:49"
      ],
      [
        5,
        "Bit Coin",
        "22.3575",
        "91.8323",
        "Chittagong",
        "Chittagong",
        "both",
        "option1",
        "$500/month",
        "30",
        "no link",
        "017000000000",
        "arifhasnat.info@gmail.com",
        "21-10-2017",
        "2017-03-01 17:43:34",
        "2017-03-01 17:43:34"
      ]
    ]
  }
} 

1 个答案:

答案 0 :(得分:2)

默认情况下,Retrofit不支持自动JSON解析。但你可以使用GSON。 https://github.com/google/gson

如何使用Retrofit和GSON解析JSON的简短教程,例如:http://www.pratikbutani.com/2016/05/android-tutorial-json-parsing-using-retrofit-part-1/

但是还有更多教程可以帮助你。