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
  • 34,719
  • 24
  • 185
  • 251
Yohanim
  • 2,999
  • 7
  • 48
  • 84

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,394
  • 5
  • 55
  • 67