1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    162
    Answers
    5
    Vote Rating
    2
    rafaelrp is on a distinguished road

      0  

    Default Answered: Problem with Json Decode in PHP

    Answered: Problem with Json Decode in PHP


    Hello!

    I'm having a problem with json decode in my PHP server.. PHP5, linux

    param:
    Code:
    data:{"cliId":""}
    php decoded:
    Code:
    data:{\"cliId\":\"\"}
    PHP put this "\" in the json and i can't get the array...

    php code
    Code:
    $arrayResponse = json_decode($_REQUEST['data']);


    Thanks!

  2. I solved this problem so:
    Code:
    list($files) = $db->sql_fetchrow($db->sql_query("SELECT files FROM *** WHERE id = ".$id));
    // echo json from php to extjs
    echo str_replace("\\", "", trim(html_entity_decode($files), "\""));

  3. #2
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,111
    Answers
    83
    Vote Rating
    30
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    Hmm strange, you format half way


    Code:
    "data": {"cliId": ""}

  4. #3
    Sencha User
    Join Date
    Jan 2011
    Location
    Russia, Moskow
    Posts
    2
    Answers
    1
    Vote Rating
    0
    semushin is on a distinguished road

      0  

    Default


    I solved this problem so:
    Code:
    list($files) = $db->sql_fetchrow($db->sql_query("SELECT files FROM *** WHERE id = ".$id));
    // echo json from php to extjs
    echo str_replace("\\", "", trim(html_entity_decode($files), "\""));

  5. #4
    Sencha User
    Join Date
    Jun 2011
    Posts
    162
    Answers
    5
    Vote Rating
    2
    rafaelrp is on a distinguished road

      0  

    Default


    I solved this problem using this functions
    Code:
    $jsonEncoded = stripslashes($_REQUEST['data']);
    $arrayResponse = json_decode($jsonEncoded);
    But i don't think is the best way...

    The best way is the php read the json without the "\"

    Thanks!

Thread Participants: 2