www.webdeveloper.com
Results 1 to 4 of 4

Thread: json_encode()

  1. #1
    Join Date
    Jul 2011
    Posts
    61

    json_encode()

    I need this script to produce: {"a":Bob,"b":Brittany} using json_encode(). currently, it produces: "'a' => Bob'b' => Brittany"
    Here's my script:

    PHP Code:
    $response "Bob, Brittany";
    $respose = array($response);
    $response explode(",",$response);
    $response2=  "'" "a" "' => " $response[0] . "'" "b" "' => " $response[1]; 

    echo 
    json_encode($response2) . '</br>'

  2. #2
    Join Date
    Oct 2008
    Location
    Seattle, Wa
    Posts
    695
    I honestly have no idea wth you're doing with the above code but
    why aren't you doing this?

    PHP Code:
    $response = array('a'=>'Bob','b'=>'Brittany');
    echo 
    json_encode($response); 
    Here's untested code that should work though, atleast up to Z.
    PHP Code:
    $arr explode(',','Bob, Brittany'); // or $str = 'Bob, Brittany';
        
    foreach($arr as &$k=>$v) { 
            
    $k chr($k)+97
        }

    echo 
    json_encode($arr); 
    I don't know if $k would need trim() someone else can answer that.
    Last edited by ehime; 09-02-2011 at 05:23 PM.
    _,-O
    O
    (_)) ubuntu -
    -`-O

  3. #3
    Join Date
    Jul 2011
    Posts
    61
    I obviously lived up to the Hahaha .... Wut? under your Avatar. I was missing a line of code. Thanks for your help ehime!

  4. #4
    Join Date
    Oct 2008
    Location
    Seattle, Wa
    Posts
    695
    Yep, no worries
    _,-O
    O
    (_)) ubuntu -
    -`-O

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles