1

I have a string of text that is encoded in such a way:

 {"itemId":"17417362","type":"0","cclass":0,"value":"100","category":null,"image":{"url":"\/\/cdn.site.com\/insight.site.com\/COS20\/_Cache\/_ImageCache\/362\/17417362.gif","height":"100","width":"80"},"burstText":"","summary":"SAVE $1.00 ON TWO","brand":"Big \u00ae","link_text":"","link_url":"","activated":"2012-09-01T00:01:00","expiration":"2012-10-31T23:59:00","isuff":"362\/17417362.gif","imagePrefix":null,"details":"when you buy TWO BOXES: Original \u00ae ...","catid":"531","catdesc":"Ready to Eat","slot":"-415","prodinfo":"when you buy TWO BOXES any flavor: Original \u00ae \u2022 \u00ae \u202 \u00ae...","cpnuse":"1","printed":null,"actiontaken":null,"printCount":null,"onCard":null,"sid":"11079187","fid":"06338174","videoURL":"","catlevel1":"107","catlevel2":"399","catlevel3":"531","catdesc1":"Foods","catdesc2":"Breakfast","catdesc3":"Ready to Eat","restricted":0},"17557036":

I've tried json_decode on this string but it fails. I think this is due to the special characters and general format. How can I clean this up for decode?

4
  • Your text is either invalid or incomplete. It ends suddenly midstream with `"17557036":' Commented Sep 15, 2012 at 2:15
  • May be you have text limits, that cuts some of your JSON. If you get it from DB, you should use big column to store it. Commented Sep 15, 2012 at 2:17
  • Could I use regex to remove this remainder? Commented Sep 15, 2012 at 3:22
  • Removed text after , $posoflastcomma = strrpos($myText,','); //Position of last comma $newText = substr_replace($myText, " ", $posoflastcomma); Commented Sep 15, 2012 at 3:51

1 Answer 1

3

Well for starters, your string terminates abruptly: "17557036": is the last of it - thus, not well-formed JSON.

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

1 Comment

After removing everything after the last } json_decod worked perfectly. Thanks!

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.