How to store a Japanese Character in json

I'm trying to save a json_encoded strings to the database but whenever i do i get this:

u30abu30bf

when saving:

カタ

how do i decode such a thing?

tried php utf8_decode and encode but i doesn't seem to work, i also tried reading the threads below:

  • PHP decoding and encoding json with unicode characters

  • difficulty passing Japanese characters(UTF-8) via json_encode

  • here is a var_dump data of $flex_encoded before passing it as a parameter:

    //this one seems to passing the right encoding
    [{"japanese_name":"u30cau30abu30cd"},{"japanese_name":"u30cau30abu30cd"}]
    

    here is the function call:

    $this->updateFlexData($game_id, $flex_encoded);
    

    here is the function for updating my db:

    function updateFlexData($game_id, $json_data)
    {
        $arrVal = array(
            'json_data'=> $json_data,
        );
    
        Db::getInstance()->autoExecute('japanese_names', $arrVal, 'UPDATE', " game_id = '".$game_id."'", false);
    }
    

    database column type is:

    `json_data` longtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
    

    my PHP version:

    PHP Version 5.3.10


    Try JSON_UNESCAPED_UNICODE

    json_encode($data, JSON_UNESCAPED_UNICODE);
    

    And instead of this u7537u6027u304cu5f7cu5973u306bu7740u3066... you're going to get 男性が彼...


    after hours of tinkering with the code i somehow made it to work: ok its maybe not the solution but:

  • when i proceed to storing json_data with this content(below) decoding json_data from database results to parse error because of the extra " quotations

    $japanese_name = json_encode($japanese_text); //returns "u30cau30abu30cd"
    
  • i just removed the " from each sides to make it just u30cau30abu30cd and then proceeded to store in the db

    $jp = str_replace(""","",$japanese_name); //returns u30cau30abu30cd
    
  • 链接地址: http://www.djcxy.com/p/47798.html

    上一篇: PHP:如何将无限或NaN编码编码为JSON?

    下一篇: 如何在json中存储日文字符