-2

I have this variable like json string i need to read it to get every value

 String data ={"sid":"48","name":"perla","email":"perla@gmail.com","pass":"613eb6402eb5164"};

i have tried to read the string with these methods:

String sid = data("sid");
String sid = data(0);
String sid = data[0];

but is no efficient

This is a string not an array string

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
jacolo
  • 1
  • 4

2 Answers2

0

If you have string like

String data = "{sid:48, name:perla, email:perla@gmail.com, pass:613eb6402eb5164}";

You can parse it as:

private void getData(String dataString) throws JSONException {

    JSONObject jsonObject = new JSONObject(dataString);

    String sid = jsonObject.getString("sid");
    String name = jsonObject.getString("name");
    String email = jsonObject.getString("email");
    String pass = jsonObject.getString("pass");

}
yatin deokar
  • 730
  • 11
  • 20
0

i found the solution using jsonobject

String data ="{"sid":"48","name":"perla","email":"perla@gmail.com","pass":"613eb6402eb5164"}";

JSONObject jobj = new JSONObject();
        try {
            jobj = new JSONObject(data);
            Log.d(LOG_TAG, jobj.toString());
            String order = jobj.getString("orderId");
        } catch (JSONException e) {
            //e.printStackTrace();
        }
jacolo
  • 1
  • 4