tags:

views:

84

answers:

4

Hi, i need decode this Json with the PHP, but i dont know how. I saw this function php.net/json, but it haven't how to decode this type of data.

{"c":[{"v":"0","e":"","n":"45","cc":"PSDB - PTB \/ PPS \/ DEM \/ PMN \/ PSDB \/ PT do B","nm":"JOSÉ SERRA","nv":"VICE: ÃNDIO DA COSTA"},{"v":"0","e":"","n":"13","cc":"PT - PRB \/ PDT \/ PT \/ PMDB \/ PTN \/ PSC \/ PR \/ PTC \/ PSB \/ PC do B","nm":"DILMA","nv":"VICE: MICHEL TEMER"}],"r":[{"f":"Oficial","dt":"30\/10\/2010","v":"1","t":"2","ht":"22:00:09","tf":"false","m":"N"}],"t":[{"vl":"0","vv":"0","e":"135804433","vnom":"0","s":"400001","c":"0","tv":"0","a":"0","vb":"0","st":"0","ea":"0","vn":"0"}]}
+1  A: 

json_decode()

$array = json_decode('{"c":[{"v":"0","e":"","n":"45","cc":"PSDB - PTB \/ PPS \/ DEM \/ PMN \/ PSDB \/ PT do B","nm":"JOSÉ SERRA","nv":"VICE: ÃNDIO DA COSTA"},{"v":"0","e":"","n":"13","cc":"PT - PRB \/ PDT \/ PT \/ PMDB \/ PTN \/ PSC \/ PR \/ PTC \/ PSB \/ PC do B","nm":"DILMA","nv":"VICE: MICHEL TEMER"}],"r":[{"f":"Oficial","dt":"30\/10\/2010","v":"1","t":"2","ht":"22:00:09","tf":"false","m":"N"}],"t":[{"vl":"0","vv":"0","e":"135804433","vnom":"0","s":"400001","c":"0","tv":"0","a":"0","vb":"0","st":"0","ea":"0","vn":"0"}]}')

print_r($array->c["v"]);
Chacha102
I think it's actually `$array->c[0]->v` or something. Json_decode unpacks it quite weird in object mode.
mario
+4  A: 

How 'bout json_decode($your_string);? Doesn't that work?

slhck
Yes! This is he answer, but i dont know how i acess this data, $obj->..... how?
Well, for example: `$obj->{'c'}` will give you the content of c. See here for an explanation: http://www.php.net/manual/en/function.json-decode.php
slhck
And please mark the question as answered.
slhck
+1  A: 
$before='{"c":[{"v":"0","e":"","n":"45","cc":"PSDB - PTB \/ PPS \/ DEM \/ PMN \/ PSDB \/ PT do B","nm":"JOSÉ SERRA","nv":"VICE: ÃNDIO DA COSTA"},{"v":"0","e":"","n":"13","cc":"PT - PRB \/ PDT \/ PT \/ PMDB \/ PTN \/ PSC \/ PR \/ PTC \/ PSB \/ PC do B","nm":"DILMA","nv":"VICE: MICHEL TEMER"}],"r":[{"f":"Oficial","dt":"30\/10\/2010","v":"1","t":"2","ht":"22:00:09","tf":"false","m":"N"}],"t":[{"vl":"0","vv":"0","e":"135804433","vnom":"0","s":"400001","c":"0","tv":"0","a":"0","vb":"0","st":"0","ea":"0","vn":"0"}]}';

print_r(json_decode($before));
DonaldIsFreak
A: 

I got it, thanks!

You need to mark the answer with the green check mark so they get some reputation. Also, if you plan on posting more please read this: http://stackoverflow.com/faq
mattalexx