Best way to store data retrieved from JSON file?
I'm hoping to store data I get from a server which sends data via JSON. I don't want anything fancy - just would like to save the data so I can play with it in excel.
Here is the JSON URL: http://re开发者_如何学Pythonalm3.castle.wonderhill.com/api/map.json
I'm extremely surprised there are no solutions out there on this yet.
What would you guys used to achieve this?
Convert the json into a text file formatted as CSV - Excel can read that. I'll come up with some sample code in PHP after dinner.
EDIT: Bah, dinner can wait.
<?php
// Download data to a string
$mapData = file_get_contents('http://realm3.castle.wonderhill.com/api/map.json');
// Convert JSON into an Array
$mapData = json_decode($mapData);
var_dump($mapData);
echo "\n";
Saved the above into test.php
and then ran it like this:
php test.php | less
and the output is a huge data structure. You'll need to extract what you want and then use fputcsv() to write the content to a file that you'll then read into Excel. The output doesn't seem to have any special characters, but if you do have a problem make sure to encode the data as CP1252 so Excel for Windows can read it.
精彩评论