I am making a WP7 app that needs to get JSON data from an external website. However, I do not want to parse the JSON directly through the app for many reasons, one being that the returned data is not always consistent.
To solve this problem, I want to write my own service in a language I know (JavaScript, PHP, RoR are preferred) to return this data in a consistent format. Instead of sending a request to the original URL, I want to be able to send a request to my service, which will then return the data.
I have no idea how to write such a service that returns up-to-date JSON from the original source. The information keeps changing very second, so I cannot statically render a page and update it every day or whatever. The data must be polled every time a user of my WP7 application wishes to look at it.
Thank you for any guidance.
EDITS for DevZer0:
echo $data
just prints Array
echo json_encode($data)
gives me this:{ "stream": [ [ "</td>BeyondTheSummit</td>13751</td></tr>" ], [ "</td>WagamamaTV</td>2653</td></tr>" ], [ "</td>VeRsuta</td>1566</td></tr>" ], [ "</td>dubasTV</td>1128</td></tr>" ], [ "</td>followJotM</td>733</td></tr>" ], [ "</td>EternaLEnVyy</td>532</td></tr>" ], [ "</td>InozemeC</td>448</td></tr>" ], [ "</td>liquidkorok</td>295</td></tr>" ], [ "</td>DotaTalkStream</td>279</td></tr>" ], [ "</td>Sheever</td>260</td></tr>" ], [ "</td>Weppas</td>215</td></tr>" ], [ "</td>BeyondTheSummit2</td>93</td></tr>" ], [ "</td>dota2russia</td>56</td></tr>" ], [ "</td>PMSyanyan</td>54</td></tr>" ] ], "vod": [ [ "</span></td>GosuCup Asia VII: Zenith vs Dreamz /w ..</td>8</td></tr>" ], [ "</span></td>Dota 2 Dire Overlord Announcer Pack (W..</td>301</td></tr>" ], [ "</span></td>Dota 2 Purge plays Drow Ranger</td>9348</td></tr>" ], [ "</span></td>Typical Mistakes vs eL'Pride BigPoi..</td>1184</td></tr>" ], [ "</span></td>Team Empire vs Oslik Gaming BigPoin..</td>1162</td></tr>" ], [ "</span></td>Dota 2 Bottom 10 - Ep. 1 (Pilot - Reje..</td>73888</td></tr>" ], [ "</span></td>iCCup vs Next kz BigPoint Battle ..</td>631</td></tr>" ], [ "</span></td>eL'Pride vs RoX KIS BigPoint Battle..</td>712</td></tr>" ], [ "</span></td>Fnatic EU vs Artyk Gaming Game 1 Big..</td>2155</td></tr>" ], [ "</span></td>Fnatic EU vs Artyk Gaming Game 2 Big..</td>1668</td></tr>" ], [ "</span></td>Fnatic EU vs Lions Pride Bigpoint Ba..</td>988</td></tr>" ], [ "</span></td>Artyk Gaming vs iCCup Bigpoint Battl..</td>666</td></tr>" ], [ "</span></td>GosuCup Asia VII: Zenith vs Mineski</td>316</td></tr>" ], [ "</span></td>Orange eSports' 'Net' - Amazing Rubick..</td>5868</td></tr>" ], [ "</span></td>DotA2 - Outshine Vol.3</td>18672</td></tr>" ] ], "dota2vods": [ [ "2w ago</td>Orange vs </span>Rising Stars</td>BO3</td></tr>" ], [ "2w ago</td>KP vs </span>ICCup</td>BO1</td></tr>" ], [ "2w ago</td>KP vs </span>Mouz</td>BO1</td></tr>" ], [ "2w ago</td>Na'Vi vs </span>RoxKiS</td>BO1</td></tr>" ], [ "2w ago</td>Power Rangers vs </span>Alliance</td>BO1</td></tr>" ], [ "2w ago</td>LGD.INT vs </span>Orange</td>BO3</td></tr>" ], [ "2w ago</td>OsG vs </span>Alliance</td>BO1</td></tr>" ], [ "2w ago</td>zRage vs </span>KP</td>BO1</td></tr>" ], [ "2w ago</td>Empire vs </span>Quantic</td>BO1</td></tr>" ], [ "2w ago</td>Empire vs </span>TCM</td>BO1</td></tr>" ], [ "3w ago</td>Empire vs </span>KP</td>BO1</td></tr>" ], [ "3w ago</td>Quantic vs </span>TCM</td>BO1</td></tr>" ], [ "3w ago</td>Empire vs </span>RoxKiS</td>BO1</td></tr>" ], [ "3w ago</td>Mouz vs </span>ICCup</td>BO1</td></tr>" ], [ "3w ago</td>4FC vs </span>Mouz</td>BO1</td></tr>" ] ] }
If i copy this raw data into JSONLint, it says the JSON is valid. However, if I put in my URL ("http://blah.com/streams.php"), it says it is invalid. I know that JSONLint can take a URL to validate, not just raw data.
Here's my full PHP file as of now (streams.php):
<?php
header("Content-Type: application/json");
$url = "http://the-website-with-json";
$json = file_get_contents($url);
$data = json_decode($json, TRUE);
return json_encode($data);
?>
Your wrapper class sounds something like this
function wrapper($data) {
$json = file_get_contents("http://.......");
$obj = json_decode($json);
//process your reconstruction consuming $obj
return json_encode($obj); //or a new object that you transformed $obj
}
Then from your main application you can call
$data = wrapper($data);
$obj = json_decode($data);