0

I have string with JSON structure like this

String response = "{'success':1,'error_code':0,'message':'Access granted'}"

I want to split that using String.split() to be like this:

{[success],[1],[error_code],[0],[message],[Access Granted]}

I have tried this solution, this solution too, but none of solution fit with my need.

How I can achieve this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Yohanim
  • 3,319
  • 9
  • 52
  • 92

1 Answers1

2

Try this way,hope this will help you to solve your problem.

try{
   JSONObject responseJson = new JSONObject("{\"success\":1,\"error_code\":0,\"message\":\"Access granted\"}");
   String valu1 = responseJson.getString("success");
   String valu2 = responseJson.getString("error_code");
   String valu3 = responseJson.getString("message");
}catch (Throwable e){
   e.printStackTrace();
}
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67