0

I have String like this. [{"passwd":"test"}] I want to get the value 'test' seperatelty to a string with out converting this to a JSON. How can I do that?

2
  • 3
    I don't understand. Why don't you use JSON parser? Commented Jan 14, 2015 at 9:18
  • You want to do basic string operation? Commented Jan 14, 2015 at 9:19

2 Answers 2

2
String jsonString = "[{\"passwd\":\"test\"}]";

String password = jsonString.substring(jsonString.indexOf("\":\"") + "\":\"".length(), jsonString.indexOf("\"}"));
Sign up to request clarification or add additional context in comments.

Comments

0
String pw = [{"passwd":"test"}];
pw = pw.replaceAll("\"\\}\\]", "").split(":\"")[1];

This is the most easiest way and it worked for me..!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.