简体   繁体   中英

How to add the another data below existing data in JSON response in Flutter?

"joint_user_detail_list": {
      "joint_user1": {
        "ihl_user_id": "lK6dlQ2NU0WNKXk5lx07Lg",
        "ihl_user_name": "Guest User",
        "status": "requested",
        "vital_read": true,
        "vital_write": true,
        "teleconsult_read": true,
        "teleconsult_write": true
      }
    }

This is the response of body from one api? I have to add another joint user 2 below this array upto 15 joint users How to do? please help

If the response body is json string you need convert it into Map Variable(ignore this step if it's already Map Variable):

Map<String,dynamic> jsonMap = JsonDecode(body);

Then just modify it like below:

jsonMap["joint_user_detail_list"]["joint_user2"] =
 {
        "ihl_user_id": "any data",
        "ihl_user_name": "any data",
        "status": "any data",
        "vital_read": true,
        "vital_write": true,
        "teleconsult_read": true,
        "teleconsult_write": true
      };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM