Parse weird formatted data to XML?
Sample output data is below, it looks something like JSON, but it's not formatted exactly like JSON. So I am wondering, how can I get this data looking like XML, preferably with php?
[{
action: 'getallregions',
reply: [{
regionid: '1',
name: 'Blue',
description: 'Research Route',
color: '508CEB',
active: 'true',
parentRegionId: '0',
parentRegion: ''
}, {
regionid: '4',
name: 'Green',
description: 'Vet School Route',
color: '73BE69',
active: 'true',
parentRegionId: '0',
parentRegion: ''
}, {
regionid: '10',
name: 'Purple',
description: 'Loop route',
color: '5300B5',
active: 'true',
parentRegionId: '0',
parentRegion: ''
}]
}]
开发者_高级运维Here is the data on Pastie.org http://pastie.org/1045154
You might be interested in topic "Is there some way to convert json to xml in PHP?"
Hope, that it helps you.
I don't know if this is what you are looking for, but:
json_decode(preg_replace('/([a-z0-9]+):/i','"$1":',str_replace('\'','"',$data)))
Basically I found a way to make the input valid JSON. The you can convert the object to xml using the XML_Serializer.
精彩评论