W
W
wera77772015-11-11 06:51:38
Java
wera7777, 2015-11-11 06:51:38

How to select data from a row and write it to two variables?

There is a line:
{"phone":"+79262545729","balance":"40"}
How can I write a number +79262545729to a variable from this line String st1;
A balance 40to a variable int bal;
It would be nice to somehow tie everything with a regular expression, but I am not familiar with them at all (

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2015-11-11
@wera7777

stackoverflow.com/questions/2591098/how-to-parse-j...

C
Chvalov, 2015-11-12
@Chvalov

try{
  JSONObject jsonObject = new JSONObject(answ);
  String st1 = jsonObject.getString("phone");
  int bal = jsonObject.getInt("balance");
  } catch (JSONException e){
    e.printStackTrace();
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question