0

I have array and converting that into json format by using json_encode($array),its working fine.but the problem the description field containg the html data and some special character is in this like(GapFree "-Version!).because of these special character json is not getting valid.but i need all data in description field also.

if i used pregmatch,all specailcharacter is escaping but description field data also removing.so how to avoid these special charater in my json data,so i can keep my data as well as json should be valid.

[{
  
  "uniquenumber": "75642",
  "Name": "moto e 6\/6S | ebony | rgb",
  "Description": "\u003Cul\u003E\n\n\t\u003Cli\u003E\n\n\t\t\u003Cspan style=\"color: rgb(74, 74, 74); font-family: VodafoneRg, sans-serif; font-size: 16px;\"\u003ERobuster, schicker Schutz mit nur 7g Gewicht und einer Dicke von 0,3mm\u003C\/span\u003E\u003C\/li\u003E\n\n\t\u003Cli\u003E\n\n\t\t\u003Cspan style=\"color: rgb(74, 74, 74); font-family: VodafoneRg, sans-serif; font-size: 16px;\"\u003ENeue "
  GapFree "-Version! - Nahtloser Übergang von Folie zum Case\u003C\/span\u003E\u003C\/li\u003E\n\n\t\u003Cli\u003E\n\n\t\t\u003Cspan style=\"color: rgb(74, 74, 74); font-family: VodafoneRg, sans-serif; font-size: 16px;\"\u003EKunststoff-Hülle mit Echtholz-Furnier und mattem Finish\u003C\/span\u003E\u003C\/li\u003E\n\n\t\u003Cli\u003E\n\n\t\t\u003Cspan style=\"color: rgb(74, 74, 74); font-family: VodafoneRg, sans-serif; font-size: 16px;\"\u003EDie T2PP-Technologie verbessert die Flexibilität und Widerstandsfähigkeit der Hülle\u003C\/span\u003E\u003C\/li\u003E\n\n\t\u003Cli\u003E\n\n\t\t\u003Cspan style=\"color: rgb(74, 74, 74); font-family: VodafoneRg, sans-serif; font-size: 16px;\"\u003EDie frische Optik des Cases unterstreicht das Design des neuen iPhone\u003C\/span\u003E\u003C\/li\u003E\n\n\t\u003Cli\u003E\n\n\t\t\u003Cspan style=\"color: rgb(74, 74, 74); font-family: VodafoneRg, sans-serif; font-size: 16px;\"\u003EInklusive zwei Displayschutzfolien für das schwarze und weiße iPhone\u003C\/span\u003E\u003C\/li\u003E\n\n\u003C\/ul\u003E\n",
 

  "DAdd": "2016-07-13 13:57:37",
  "DUpd": "2017-07-11 09:42:43"
 }]
bhatt
  • 135
  • 1
  • 14
  • have a look- https://stackoverflow.com/questions/2410342/php-json-decode-returns-null-with-valid-json – Dharmesh patel Aug 29 '17 at 06:05
  • @Dharmeshpatel: i tried with above links,but did't get any proper solution.description field is still contains special character – bhatt Aug 29 '17 at 06:36
  • Why do you think that JSON is invalid‽ – deceze Aug 29 '17 at 06:54
  • @deceze: i have copy complete data and past into online json validator, there its showing INVALID JSON.showing below error Error: Parse error on line : ...px;\"\u003ENeue " GapFree "-Version! - ----------------------^ Expecting 'EOF', '}', ':', ',', ']', got 'undefined' – bhatt Aug 29 '17 at 06:58
  • If you are using `json_encode` to produce this JSON and you're not monkeying around with it afterwards, it *must* be valid JSON. You're somehow mistreating and breaking the JSON after encoding it. – deceze Aug 29 '17 at 07:28

1 Answers1

0

json_encode() escapes all special characters in UNICODE format (escape sequence \uXXXX), but for that conversion to work properly, all input strings must be in UTF-8 format. Make sure input is properly encoded in UTF-8 and the output should be correct.

Havenard
  • 27,022
  • 5
  • 36
  • 62