-4

I am getting a JSONObject in response from an API

{
"contact": null,
"error": false,
"msg": "get Contacts successfully",
"synccontactstimestamp": "2018-02-07 11:34:40.0",
"contactjson": "[{\"contactName\":\"4B9B4474C091D55A981ADBB7893FB4E1\",\"contactNumber\":\"0F8F3E9514D329F32CE7B03B9D276D72\"}, {\"contactName\":\"12E09C05C0E456AC2398BDA841986609\",\"contactNumber\":\"035774DB94BFE24BDEDA0B4B45F1372A0CC8EE72A457C3AAA35F79627FD13728\"}, {\"contactName\":\"9344BBF08ACACC4C85A9B83C55BA93C0\",\"contactNumber\":\"E1633601A6632356DB2F08058CA42504\"}, {\"contactName\":\"CCF51D9C27123ACD19F163F6C2BCCD28\",\"contactNumber\":\"89DD6C0E185D1067AC45CEE12DFA6A07\"}, {\"contactName\":\"A8309A8EC81E4DF50306FE4651D63F53\",\"contactNumber\":\"E8781EE87E9036B794BE44D7411FBFCF\"}

I am trying to get this JSONArray with key "contactjson" but it gives an exception Value of string type cannot be converted to JSONArray.

Any idea how to fetch this?

Neemani
  • 1
  • 4

1 Answers1

1

as you see value of contactjson key is coming as String,

First take your contactjson into a String variable like

 String data = yourResponse.contactjson;

then convert into JSONArray

 JSONArray jsonArr = new JSONArray(data);
Sachin Rajput
  • 4,326
  • 2
  • 18
  • 29