0

I am trying to get the car positions (if I can the cars state (gas, how clean, etc) from this site: https://carsharing.mvg-mobil.de/?ref=separate.

As far as I can tell they get their data from this URL:

https://carsharing.mvg-mobil.de/json/stations.php

Now I am having trouble converting that into usable XML format. I tried bringing it into String form by using

JSON.stringify() 

and go from there but that didn't seem to work. What im having trouble with are the { and quotation marks

2
  • https://carsharing.mvg-mobil.de/json/stations.php is a JSON file. It needs to be decoded into an object. Try using PHP's json_decode() (or JavaScript's JSON.parse()). Commented Oct 20, 2015 at 14:04
  • JSON.stringify() encodes an object/array as an JSON string. That's the wrong direction here. You already have a string. Commented Oct 20, 2015 at 14:05

1 Answer 1

2

since your question is tagged as php, here is a simple code-snippet that will get you a xml-string:

<?php
//get json-string
$cars_json = file_get_contents("https://carsharing.mvg-mobil.de/json/stations.php");
//convert json to array
$cars_array = json_decode($cars_json,true);

//creat xml-object and fill recursive
$xml = new SimpleXMLElement('<root/>');
array_walk_recursive($cars_array, array ($xml, 'addChild'));

//create xml-string that can be saved
$cars_xmlstring = $xml->asXML();
echo $cars_xmlstring
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Pre-processing data with your server as a proxy is a good thing, so Depending how you want to use this data.. PHP would allow for more options

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.