javascript - How to decode encoded json to HTML JS -


i using drupal json field formatter encode html body field.

i got result in json

"\"\u2022 big eggplant\r\n\u2022 2 tomatoes cut in slices\r\n\u2022 1 green pepper cut in slices\r\n\u2022 250gm minced meat\r\n\u2022 \u00bdtbsp of salt\r\n\u2022 \u00bdtbsp dried oregano\r\n\u2022 1tsp black pepper\r\n\u2022 \u00bd cup chopped onions\r\n\u2022 \u00bc cup oil cook meat\"" 

how can decode using js ?

i tried code not working fine

function htmlbody(x){         var bodi=''; bodi=x.replace('\n', '<br />')                  // removes encoded newline characters bodi=x.replace('\t', '')                  // removes encoded tab characters bodi=x.replace(/(?:\s+)?<(?:\s+)?/g, '<') // removes whitespace before or after tag-start delimiter. bodi=x.replace(/(?:\s+)?>(?:\s+)?/g, '>') // removes whitespace before or after tag-stop delimiter. bodi=x.replace(/\s+/g, ' '); return bodi; } 

my suspicion have close ...

try ...

function htmlbody(x){   var bodi='';   bodi=x.replace('\n', '<br />')                  // removes encoded newline characters   // point, bodi corrected version; x has not been changed.   bodi=body.replace('\t', '')                  // removes encoded tab characters   bodi=bodi.replace(/(?:\s+)?<(?:\s+)?/g, '<') // removes whitespace before or after tag-start delimiter.   bodi=bodi.replace(/(?:\s+)?>(?:\s+)?/g, '>') // removes whitespace before or after tag-stop delimiter.   bodi=bodi.replace(/\s+/g, ' ');   return bodi; } 

you might take @ ... json2html.com


Comments

Popular posts from this blog

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

java - Reading data from multiple zip files and combining them to one -