dongtan7998 2016-06-20 03:29
浏览 169
已采纳

如何JSON编码具有HTML标签的数据?

I have a products data with products information. It's actually in form of array but I tried to use json_encode function to convert it into JSON response.

The problem is it has some HTML code inside product description so it's showing some lines.

Link : http://superwholesalebazaar.xyz/wocom.php

Why it's showing the lines ? Isn't it the JSON response ?

Thanks!

  • 写回答

1条回答 默认 最新

  • dtsps2098 2016-06-20 03:38
    关注

    Its showing the lines because in the HTML part of the data you have elements which naturally have the line strikethrough style associated with it such as the <del> element.

    But since its a json response and you are sending it as a text/html type the browser renders it all as HTML and since json encode escapes some of the characters in the HTML its showing up a little weird such as some elements aren't closed properly.

    I think what you want to do is send this response with the content type set to "json"

    Here is how you can do this in php:

    header('Content-Type: application/json');
    // echo your json content here
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?