0

I have an array width an object which Iam trying to json_decode: My problem is that iam not sure how to make the right json_encoding and afterwords decode.

  Array (
    [id] => 22
    [infotext] => {"2":"<p>da</p>
    ","3":"<p>en</p>
    "}
    [language_status] => {"2":{"status":"0"},"3"}
  )

Decoding the [language_status] gives me:

 var_dump(json_decode($arr['language_status']))

 stdClass Object (
   [2] => stdClass Object ( 
      [status] => 0
    )
   [3] => stdClass Object ( 
      [status] => 0
    )
  )

which is fine, but my problem is that i can't seem to get an output when json decoding [infotext]. Iam sure it is because the html tags, but just cant get the right input/output the get this to work.

I would love to see the [infotext] output somewhere like this:

 var_dump(json_decode($arr['infotext']))

 stdClass Object (
   [2] => <p>da</p>
   [3] => <p>en</p>
  )

Please help me solve this

Ok i managed to recreate my problem and i found out its when i create the Json object the problem occurs: http://codepad.viper-7.com/SG175W

As you can see the JSon object has breaks in the array which is creating the problem. Any easy way to remove em?

3
  • 1
    Cannot reproduce Commented Nov 18, 2014 at 12:10
  • 1
    As above, the json in this question is valid. Can you recreate your problem and share the reproducible code, ideally somewhere it can be ran, like codepad.viper-7.com Commented Nov 18, 2014 at 12:27
  • Updated and recreated issue on codepad.viper! Commented Nov 18, 2014 at 13:21

2 Answers 2

2

Try this,

var_dump(json_decode($arr['language_status']),true);

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

2 Comments

var_dump(json_decode($arr['infotext']),true); returns NULL bool(true)
appreciate your trying to help, instead of just devoding ;)
1

This must work, maby you can change it in your way.

<?php

$infotext = json_decode('{"2":"<p>da</p>","3":"<p>en</p>"}');

foreach($infotext as $text){
echo $text;
}
?>

1 Comment

Your right it should, and it does, apparently my problem is something else :/

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.