json对象的转换,新手求大神帮忙
json格式如下
{"loginResult":{"code":"005","teamId":"1","password":"123","role":"员工","roleId":"2"}}
我用的CI框架 在models 里面定义了一个Member_Model对象,属性有code,teamId,password,role,roleId
怎样将上面的JSON数据转换成对象赋给Member_Model
------解决方案--------------------
$json = '{"loginResult":{"code":"005","teamId":"1","password":"123","role":"员工","roleId":"2"}}';<br />$arr = json_decode($json);<br />$mm = new Member_Model();<br />foreach ($arr->loginResult as $key => $value) {<br /> $mm->$key = $value;<br />}
$s='{"loginResult":{"code":"005","teamId":"1","password":"123","role":"员工","roleId":"2"}}';<br />$o = json_decode($s);<br />print_r($o->loginResult);