【问题标题】:Java-Json Parsing issue-Escaping the XML characters [closed]Java-Json 解析问题 - 转义 XML 字符 [关闭]
【发布时间】:2013-09-25 05:52:19
【问题描述】:

我无法在 Json 响应中转义 XML 字符。 这是 JSON 响应

{"projectId":14,"modificationDate":1379677731000,"projectJsonData":"{"playerConfig":{"autoPlay":true,"initVolume":"50","initFullScreen":false,"size":"container","splashPoster":"defailt.png","projectId":123456},"formList":[{"type":"form","subType":"form-image","position":"inscreen","transition":"comealive-fade","width":50,"zindex":998,"start":12.9125390745513,"end":16.90343280291607,"id":"complexForm1","layout":"formTemplate","imgSrc":"images/birds.jpg","title":"Gannets usually found in Australia..","desc":"The birds that you see in this video are Gannets usually found in Australia and New Zealand. Diving birds are birds which plunge into water to catch fish or other food. They may enter the water from flight, as does the brown pelican or they may dive from the surface of the water. More than likely they evolved from birds already adapted for swimming that were equipped with such adaptations as lobed or webbed feet for propulsion.","button":[{"title":"Gannets","action":"http://en.wikipedia.org/wiki/Gannet","type":"link"},{"title":"Aussie Gannet","action":"http://en.wikipedia.org/wiki/Australasian_Gannet","type":"link"},{"title":"Photography","action":"http://aloneatseaphotography.com.au/8950","type":"link"}],"displayType":"non-intrusive","action":"internal-seek"},{"type":"form","subType":"form-video","start":26.9125390745513,"end":35.90343280291607,"target":"video-container","position":"custom","transition":"comealive-fade","id":"complexForm2","layout":"formTemplate","videoSrc":[{"src":"videos/ocean.mp4","type":"video/mp4","codecs":"vp8,vorbis"},{"src":"videos/ocean.webm","type":"video/webm","codecs":"vp8,vorbis"}],"title":"Slow Motion","desc":"Gannets in super slow-mo","button":[],"displayType":"non-intrusive","tags":"Gannets","action":"internal-seek"},{"type":"form","subType":"form-custom","start":4,"end":10,"target":"video-container","position":"custom","id":"complexForm3","layout":"custom","title":"Gannets","content":"%3Cimg%20style%3D%22position%3Aabsolute%3Bright%3A10%25%3Btop%3A20px%22%20width%3D%22150%22%20height%3D%22150%22%20src%3D%22images%2Fbirds.jpg%22%20%2F%3E","displayType":"intrusive-parallel","desc":"Gannets","tags":"Gannets","action":"internal-seek","animation":"slideIn-600-easeOutBounce"}

由于这里的大小限制,我给出了部分 Json 响应。 我已经使用以下内容来解析响应

JSONObject jsonProjectDataObject = new JSONObject( StringEscapeUtils.escapeXml(videoGetResponse.get("projectJsonData").toString()));

现在我得到了例外

org.json.JSONException: Expected ':' after &quot at character 7 of {"playerConfig":{"autoPlay":true,"initVolume":"50","initFullScreen&quot

【问题讨论】:

  • 它的json无效,有什么问题?
  • 在 & 符号之前有效。检查:jsonviewer.stack.hu
  • 完全是合法的JSON

标签: java android xml json


【解决方案1】:

JSON 不是 XML。使用 XML 实体不是转义 JSON 的合适方式。

使用 XML 实体转义的双引号:"

使用 JSON 转义双引号:\"

【讨论】:

  • 没听明白!
  • @user2813821 不要使用 XML 转义方法“StringEscapeUtils.escapeXml”转义 json 字符串
【解决方案2】:

粘贴你的输出 here 它说它的 json 无效。在解析 json 之前检查这个链接

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-25
    • 1970-01-01
    • 2015-11-19
    • 2021-06-13
    • 2012-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多