/    Sign up×
Community /Pin to ProfileBookmark

help! how to use json in php?

i have seen many example of how to work with json but my problem is i dont know if there some software or class or whatever i need to install or to include in my page just to make the json work.. i try this code but it doesn’t work

this was the code i got from the internet:

[CODE]Documentation
A simple ./configure; make; make install should do the trick. Make sure to add an extension=json.so line to your php.ini/php.d.

Then, just use json_encode to encode your PHP values into JSON, and json_decode to decode JSON into a PHP value.

For example:

$val = array(“abc” => 12,
“foo” => “bar”,
“bool0” => false,
“bool1” => true,
“arr” => array(1, 2, 3, null, 5),
“float” => 1.2345
);
$output = json_encode($val);
echo $output.”n”;
Would produce:

{ “abc”: 12, “foo”: “bar”, “bool0”: false, “bool1”: true, “arr”: [ 1, 2, 3, null, 5 ], “float”: 1.234500 }
While:

$input = ‘{ “abc”: 12, “foo”: “bar”, “bool0”: false, “bool1”: true, “arr”: [ 1, 2, 3, null, 5 ], “float”: 1.234500 }’;
$val = json_decode($input);
echo $val->abc.”n”;
Would produce:

12
[/CODE]

the php error said that the function json_encode($val); Does not seen… that example can be found in [url]http://www.aurore.net/projects/php-json/[/url]… please somebody help me..

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@scragarNov 06.2007 — ok, from the top are you running it on a unix server, and did you follow the first 3 steps to compile it?

if not the line is:./configure && make && make install
did you add the json.so extention line to php.d? if so did you try a full link(eg /usr/lib/...)?
Copy linkTweet thisAlerts:
@johnixauthorNov 08.2007 — thanks for your reply scragar... i already got it.. i just upgrade my php to php 5.0....
×

Success!

Help @johnix spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...