How to filter data when xml is converted to json?

Source: Internet
Author: User
How to filter data when xml is converted to json? JSON XML

The xml below is converted to json
But under the P node, only The data of these two nodes is not required for other data.
If you use json_encode to transfer out all the data
How can I convert it to json, but as long How to get the data?

For example
{"PN": "\ u7b2c \ u4e00 \ u5468 \ u64ad \ u5267 \ u573a \ uff1a \ u8ffd \ u9c7c \ u4f20 \ u5947 31", "PT": "22:01:00 "}

------- Xml ---------



110171675
Zhang San
2013-08-19 00:02:00
46
24
74750
0
2013-08-19 00:02:00
AM



110171676
I am a beauty
2013-08-19 01:15:00
46
24
74501
0
2013-08-19 01:15:00
AM



110171677
Li Si
2013-08-19 02:09:00
46
24
64519
71411
2013-08-19 02:09:00
AM




Reply to discussion (solution)

$ String = <
       
      

110171675 Zhang San 2013-08-19 00:02:00 46 24 74750 0 2013-08-19 00:02:00 AM

110171676 I am a beauty 2013-08-19 01:15:00 46 24 74501 0 2013-08-19 01:15:00 AM

110171677 Li Si 2013-08-19 02:09:00 46 24 64519 71411 2013-08-19 02:09:00 AM

XML; $ xml = simplexml_load_string ($ string); foreach ($ xml-> P as $ item) {$ item = (array) $ item; $ arr [] = array ('pn '=> $ item ['pn'], 'pt' => $ item ['pt']);} echo json_encode ($ arr );

[{"PN": "\ u5f20 \ u4e09", "PT": "00:02:00" },{ "PN ": "\ u6211 \ u662f \ u5927 \ u7f8e \ u4eba", "PT": "01:15:00" },{ "PN": "\ u674e \ u56db", "PT ": "2013-08-19 02:09:00"}]

$ Xml = <XML
       
      

110171675 Zhang San 2013-08-19 00:02:00 46 24 74750 0 2013-08-19 00:02:00 AM

110171676 I am a beauty 2013-08-19 01:15:00 46 24 74501 0 2013-08-19 01:15:00 AM

110171677 Li Si 2013-08-19 02:09:00 46 24 64519 71411 2013-08-19 02:09:00 AM

XML; $ sm = simplexml_load_string ($ xml); foreach ($ sm-> P as $ item) {$ r [] = array ('pn '=> strval ($ item-> PN), 'pt' => strval ($ item-> PT ));} echo json_encode ($ r );
[{"PN": "\ u5f20 \ u4e09", "PT": "00:02:00" },{ "PN ": "\ u6211 \ u662f \ u5927 \ u7f8e \ u4eba", "PT": "01:15:00" },{ "PN": "\ u674e \ u56db", "PT ": "2013-08-19 02:09:00"}]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.