JSON object conversion, novice ask God Help
The JSON format is as follows
{"Loginresult": {"code": "005", "Teamid": "1", "Password": "123", "Role": "Employee", "Roleid": "2"}}
I used the CI framework to define a Member_model object in models, with attributes Code,teamid,password,role,roleid
How to convert the above JSON data into objects to assign to Member_model
------Solution--------------------
$json = ' {' Loginresult: {' Code ': ' 005 ', ' teamid ': ' 1 ', ' Password ': ' 123 ', ' role ': ' Employee ', ' Roleid ': ' 2 '} ';
$arr = Json_decode ($json);
$mm = new Member_model ();
foreach ($arr->loginresult as $key = + $value) {
$mm $key = $value;
}
------Solution--------------------
$s = ' {' Loginresult: {' Code ': ' 005 ', ' teamid ': ' 1 ', ' Password ': ' 123 ', ' role ': ' Employee ', ' Roleid ': ' 2 '} ';
$o = Json_decode ($s);
Print_r ($o->loginresult);
------Solution--------------------
If it is
$result = Json_decode ($buffer, true);
The
$member = $result [' Loginresult '];
If it is
$result = Json_decode ($buffer);
The
$member = $result->loginresult;