0

I am working on an multilanguage application and we use utf8_genral_ci to store information in multilanguage. information store correctly in database but json encoding give me data in improper formate.

these are what i am getting from server

{"Result":[{"id":"1","name":"\u0939\u093f\u0902\u0926\u0940","admin_id":"29","active":"yes","time":"2013-06-04 03:26:47"},{"id":"2","name":"\u4e2d\u570b\u7684","admin_id":"29","active":"yes","time":"2013-06-04 03:27:11"},{"id":"3","name":"fran\u00e7ais","admin_id":"29","active":"yes","time":"2013-06-04 03:27:34"}]}

while i want to convert/save result in these formate

{
"Result": [
    {
        "id": "1",
        "name": "हिंदी",
        "admin_id": "29",
        "active": "yes",
        "time": "2013-06-04 03:26:47"
    },
    {
        "id": "2",
        "name": "中國的",
        "admin_id": "29",
        "active": "yes",
        "time": "2013-06-04 03:27:11"
    },
    {
        "id": "3",
        "name": "français",
        "admin_id": "29",
        "active": "yes",
        "time": "2013-06-04 03:27:34"
    }
]

}

Thanks in advance.

David H
  • 40,852
  • 12
  • 92
  • 138
Suraj Gupta
  • 200
  • 9

1 Answers1

1

From the looks of your string, the unicode is not encoded in the string as UTF8, but as its representation. That is, if I craft a static string, I use \u..., but the compiler sees that and creates UTF8. When you see \u... in a string received from a server, it means it has been created using \ \u... - the \ was escaped. My guess is that you need to process the strings, looking for \uxxxx, and replace those with the real UTF8 for that code point.

David H
  • 40,852
  • 12
  • 92
  • 138
  • 1
    Actually, with json_decode it's not needed to do this as it decodes those escape sequences automatically. – Evert Jun 06 '13 at 13:00
  • @Evert this was originally tagged as iOS, which is where I saw it. Not a php guy so was unaware, this is obviously the way to decode it, so thanks for updating my answer. – David H Jun 06 '13 at 13:40