-
- $json_string='{"id":1,"name":"foo","email":"foo@foobar.com","interest":["wordpress","php"]} ';
- $obj=json_decode($json_string);
- echo $obj->name; //prints foo
- echo $obj->interest[1]; //prints php
- ?>
复制代码
2、解析XML 数据
I)、xml文件
-
- $xml_string="
- Foo
- foo@bar.com
- Foobar
- foobar@foo.com
- ";
复制代码
II)、解析xml的代码
-
-
//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, '
';
- }
- ?>
-
复制代码
|