Parse Json to String android studio

后端 未结 4 1379
Happy的楠姐
Happy的楠姐 2021-01-19 14:58

I have this JSON object:

{
  \"1\":{
    \"id_module\":\"f83d6101cc\",
    \"adresse_mac\":\"00:6A:8E:16:C6:26\",
    \"mot_de_passe\":\"mp0001\",\"name\":\         


        
相关标签:
4条回答
  • 2021-01-19 15:43

    I recommend using gson from Google.

    Check out this tutorial

    GSON Makes live way more handable!

    0 讨论(0)
  • 2021-01-19 15:45

    You should try this:

    String str = "your json string";
    JSONObject json = new JSONObject(str);
    String module = json.getJSONObject("1").getString("id_module");
    String address = json.getJSONObject("1").getString("adresse_mac");
    String module2 = json.getJSONObject("2").getString("id_module");  //from 2nd object
    
    0 讨论(0)
  • 2021-01-19 15:53

    Try this:

    String json = {"1":{"id_module":"f83d6101cc","adresse_mac":"00:6A:8E:16:C6:26","mot_de_passe":"mp0001","name":"a"},"2":{"id_module":"64eae5403b","adresse_mac":"00:6A:8E:16:C6:26","mot_de_passe":"mp0002","name":"a"}}
    

    Then:

    JSONObject obj = new JSONObject(json);
    

    Hope it will help.

    0 讨论(0)
  • 2021-01-19 15:55

    You may also check Jackson for a performance bonus.

    Tutorial: JackSon in 5 minutes

    or Gson by Google for a kinda more elegant api.

    0 讨论(0)
提交回复
热议问题