/    Sign up×
Community /Pin to ProfileBookmark

Can’t send properly formatted JSON from .json file

[code=php]$file_name = $res[‘fileName’];
$file = file_get_contents($file_name);

$obj = json_decode($file,true);

echo $_GET[‘callback’] . ‘(“‘ . json_encode($obj) . ‘”);’;[/code]

That’s my script.

this is the .json file

[code=html]{“topic”:{“prefix”:”www.mysocialbeacon.com/files/tutorial/”,”slides”:[{“prefix”:”general/”,”topic”:”General”,”img”:”1.png”,”title”:”Welcome”]}}[/code]

basically I’m trying to return it to a javascript file and it’s wrapping quotes around the wrong part. Here’s the beginning of the response

“{“topic”:{“prefix”:”www.mysocialbeacon.com/files

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@svidgenOct 05.2011 — Not really sure what you want here, but two questions come to mind ...

  • 1. Why are you decoding and [B]re[/B]-encoding the JSON? (If the file is JSON anyway, why not just send it as-is?)


  • 2. Why are you wrapping the JSON object in quotes at all?
  • Copy linkTweet thisAlerts:
    @Marius_MiliunasauthorOct 05.2011 — Ok yea, i forgot that I was wrapping the callback in quotes. thx
    ×

    Success!

    Help @Marius_Miliunas 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 6.18,
    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: @nearjob,
    tipped: article
    amount: 1000 SATS,

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

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...