Pregunta

i am getting response from data services after that to create JSON Array from string it showing exception, this is my code

response = client.execute(request);
// getJSONString(response);
entity = response.getEntity();
int length = (int) entity.getContentLength();
StringBuffer sb = new StringBuffer(length);
if (entity.getContentLength() != 0) {
   reader = new InputStreamReader(entity.getContent(), "UTF-8");

   String line = "";

   BufferedReader bufferedReader = new BufferedReader(reader);
   while((line = bufferedReader.readLine()) != null)
       result += line;
   reader.close();

   jar = new JSONArray(result);**this statement getting exception**
   for (int i = 0; i < jar.length(); i++) {
      try {
         JSONObject c = jar.getJSONObject(i);
         String vtype = c.getString("ChannelID");
         res.setText(""+vtype);
      } catch (JSONException e) {
        e.printStackTrace();
      }
   }
}

this is response in string this is my response in string result:

{
    "d":[{
    "__metadata":{
        "id":
        "XXX.XX.xX.XX:33396/FalconCPDataService.svc/DESystemOptions(guid'ca08834a-da4b-4bdd-9def-c91a7ea098b5')", "uri":
        "XXX.XX.xX.XX:33396/FalconCPDataService.svc/DESystemOptions(guid'ca08834a-da4b-4bdd-9def-c91a7ea098b5')", "type":
        "FalconCP_3_1Model.DESystemOption"
    },"DEOptionsLock":{
        "__deferred":{
            "uri":
            "XXX.XX.xX.XX:33396/FalconCPDataService.svc/DESystemOptions(guid'ca08834a-da4b-4bdd-9def-c91a7ea098b5')/DEOptionsLock"
        }
    },"ID":"ca08834a-da4b-4bdd-9def-c91a7ea098b5", "ApplicationType":0, "OptionsLocksID":
    "dd1f2e09-68c4-42ac-bfdf-afdb8d4bf631", "DefaultPulsewidth":230, "DefaultRate":40, "CreatedDate":
    "\/Date(1373465393870)\/", "IndicationType":1
    }]
}

at bold statement i am getting an exception. need help to solve this

¿Fue útil?

Solución

try this:

JSONObject jo = new JSONObject(result)
jar = jo.getJSONArray("d");
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top