-
- $json_string='{"id":1,"name":"foo","email":"foo@jbxue.com","interest":["wordpress","php"]} ';
- $obj=json_decode($json_string);
- echo $obj->name; //prints foo
- echo $obj->interest[1]; //prints php
复制代码
2,PHP解析XML 数据
-
-
$xml_string="
-
- Test
- test@jbxue.com
- News
- fnews@jbxue.net
";
//load the xml string using simplexml
- $xml = simplexml_load_string($xml_string);
//loop through the each node of user
- foreach ($xml->user as $user)
- {
- //access attribute
- echo $user['id'], ' ';
- //subnodes are accessed by -> operator
- echo $user->name, ' ';
- echo $user->email, '
';
- }
-
复制代码
如今,json在数据传输上的应用越来越广了,建议大家好好掌握下。
|