0

I have database query result in php array as below:

Array
(
    [status] => 1
    [message] => Successfully Login
    [request] => Array
        (
            [firstName] => Jugni
            [lastName] => Patel
            [popup_message] => To login to this portal you have to agree out terms and condition
• L80 – R169 pm x 24 on SMARTCHAT 1GB
• G3 Beat – R259 pm x 24 on SMARTCHAT 1GB
• G3 – R399 pm x 24 on SMARTCHAT 1GB
Top 5 MTN Sales consultants for period 2-8 March 2015, on G3 & G3 Beat sales will WIN R500 each! You have until Monday 9 March 9AM to log your sales for this competition!
        )

)

When i am doing json_encode of above array then it is giving null value in description.

{"status":"1","message":"Successfully Login","request":{"firstName":"Jugni","lastName":"Patel","popup_message":null}}

Update:

Now i am able to get the value of description using utf8_encode method. But when i am again decoding that string using json_decode then it is giving below output:

It giving decode value as below:

stdClass Object
(
    [status] => 1
    [message] => Successfully Login
    [request] => stdClass Object
        (
            [firstName] => Jugni
            [lastName] => Patel
            [popup_message] => To login to this portal you have to agree out terms and condition
• L80 – R169 pm x 24 on SMARTCHAT 1GB
• G3 Beat – R259 pm x 24 on SMARTCHAT 1GB
• G3 – R399 pm x 24 on SMARTCHAT 1GB
Top 5 MTN Sales consultants for period 2-8 March 2015, on G3 & G3 Beat sales will WIN R500 each! You have until Monday 9 March 9AM to log your sales for this competition!
        )

)

Does anybody know how can i get same value of description field after json_encode?

3
  • How do you create the php array? Can you post the piece of code where you add the 'popup_message' in it? Commented Sep 1, 2015 at 10:57
  • $result=array('status'=> '1',"message"=>"Successfully Login","request"=>array("firstName"=>$row['Name'],"lastName"=>$row['Surname'],"popup_message"=>($row['Description']))); } print_r(json_encode($result)); Commented Sep 1, 2015 at 11:22
  • I see your edited answer, you get this data because the page where you print the result is not encoded in UTF-8. Put <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> on top of your page outside the php tag. Commented Sep 1, 2015 at 11:47

1 Answer 1

1

Please make sure that the string in your array is utf8-encoded. json_encode requires utf8-encoded strings and will return false on faliure.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your reply. Its working but facing issue while decode that encoded string using utf8_encode method.
You have to use utf8_decode to decode the utf8-encoded string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.