mardi 5 mai 2015

having problems parsing gson

I am trying to parse data from here http://ift.tt/1GJqrvW

in particular this part

RATES: {
 RS: [
      {
          BEG: "12:00 AM",
          END: "2:00 AM",
          RATE: "0",
          RQ: "No charge"
      },
      {
          BEG: "2:00 AM",
          END: "6:00 AM",
          RATE: "0",
          RQ: "Str sweep"
      },
      {
          BEG: "6:00 AM",
          END: "12:00 AM",
          RATE: "0",
          RQ: "No charge"
      }
  ]
},

and I have this code

if (dataObject.getAsJsonObject("RATES").isJsonObject()){
  JsonObject rates = dataObject.getAsJsonObject("RATES");
  if (rates.getAsJsonArray("RS").isJsonArray()){
      //parse stuff
  }
}

I get com.google.gson.JsonObject cannot be cast to com.google.gson.JsonArray in here

 if (rates.getAsJsonArray("RS").isJsonArray())

and If I change that to

if (rates.getAsJsonObject("RS").isJsonObject())

I get com.google.gson.JsonArray cannot be cast to com.google.gson.JsonObject

Aucun commentaire:

Enregistrer un commentaire