-2

我无法在 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

4

2 回答 2

2

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

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

使用 JSON 转义双引号:\"

于 2013-09-25T05:59:46.327 回答
0

将您的输出粘贴到此处,它说它的 json 无效。在解析 json 之前检查这个链接

于 2013-09-25T06:00:59.737 回答