json-break-html中的特殊字符
Special characters from json break html
本文关键字:特殊字符 json-break-html 更新时间:2023-09-26
我正在使用api,这是json中的一个',它破坏了我的html。
function heroSkills(id){
heroSkill = [];
$.ajax({
type: "GET",
async: false,
url: "js/champs_v2.json",
dataType: "json",
success: function(data){
$(data.data).each(function(index,value){
var listSkills = value;
for(ls in listSkills){
if(listSkills[ls].id == id){
// console.log(listSkills[ls].passive.image.full);
heroSkill.push({passive_name:listSkills[ls].passive.name,passive_description:listSkills[ls].passive.description,passive_image:listSkills[ls].passive.image.full});
for(la in listSkills[ls].spells){
champSkill = listSkills[ls].spells[la];
skillImage = champSkill.image.full;
skillDescription = champSkill.description;
skillName = champSkill.name;
heroSkill.push({skill_name:skillName,skill_description:skillDescription,skill_image:skillImage});
}
}
}
});
heroSkill.push({version:data.version});
}
});
return heroSkill;
}
然后我像这个一样输出
var AhriTest = heroSkills("40");
console.log(AhriTest);
$('.passive').append("<img src='http://ddragon.leagueoflegends.com/cdn/"+AhriTest[5].version+"/img/passive/"+AhriTest[0].passive_image+"' class='imageClipSmall img-responsive' alt='pas' data-toggle='tooltip' data-html='true' data-placement='right' title=' <p> <h5> " + AhriTest[0].passive_name + " </h5> <small>" + AhriTest[0].passive_description + " </small> </p>' >");
$('.HeroSkillQ').append("<img src='http://ddragon.leagueoflegends.com/cdn/"+AhriTest[5].version+"/img/spell/"+AhriTest[1].skill_image+"' class='imageClipSmall' alt='pas' data-toggle='tooltip' data-html='true' data-placement='right' title=' <p> <h5> " + AhriTest[1].skill_name + " </h5> <small>" + AhriTest[1].skill_description + " </small> </p>' >");
$('.HeroSkillW').append("<img src='http://ddragon.leagueoflegends.com/cdn/"+AhriTest[5].version+"/img/spell/"+AhriTest[2].skill_image+"' class='imageClipSmall' alt='pas' data-toggle='tooltip' data-html='true' data-placement='right' title=' <p> <h5> " + AhriTest[2].skill_name + " </h5> <small>" + AhriTest[2].skill_description + " </small> </p>' >");
$('.HeroSkillE').append("<img src='http://ddragon.leagueoflegends.com/cdn/"+AhriTest[5].version+"/img/spell/"+AhriTest[3].skill_image+"' class='imageClipSmall' alt='pas' data-toggle='tooltip' data-html='true' data-placement='right' title=' <p> <h5> " + AhriTest[3].skill_name + " </h5> <small>" + AhriTest[3].skill_description + " </small> </p>' >");
$('.HeroSkillR').append("<img src='http://ddragon.leagueoflegends.com/cdn/"+AhriTest[5].version+"/img/spell/"+AhriTest[4].skill_image+"' class='imageClipSmall' alt='pas' data-toggle='tooltip' data-html='true' data-placement='right' title=' <p> <h5> " + AhriTest[4].skill_name + " </h5> <small>" + AhriTest[4].skill_description + " </small> </p>' >");
json-it-self太大了,所以这里只是一个屏幕就成了问题http://puu.sh/fAnBB/f735ab544c.png/Untitled-4.png如果需要,可以全部发布。
处理此类问题的一种方法是在传递属性时使用双引号
$('.passive').append("<img src='"http://ddragon.leagueoflegends.com/cdn/"+AhriTest[5].version+"/img/passive/"+AhriTest[0].passive_image+"'" class='"imageClipSmall img-responsive'" alt='"pas'" data-toggle='"tooltip'" data-html='"true'" data-placement='"right'" title='" <p> <h5> " + AhriTest[0].passive_name + " </h5> <small>" + AhriTest[0].passive_description + " </small> </p>'" >");
您可以对其余字符串重复转义双引号,这样可以防止字符串在连接时断开。
同样仅供参考,title属性中的标记并没有任何作用,除非它们以某种方式被javascript处理。
相关文章:
- 如何解析json中的特殊字符
- JSON编码一个包含#和其他特殊字符的字符串
- 用Javascript替换从JSON中获取的数组数据特殊字符
- json-break-html中的特殊字符
- Titanium Mobile JSON 和 Android 中的特殊字符
- 将特殊字符字符串到 JSON 字符串化非法令牌中
- 使用特殊字符解析 JSON
- 如何在JSON字符串中使用特殊字符
- 如何使用带有特殊字符的jquery解析Json
- 通过某些特殊字符或字符序列进行拆分来解析JSON输出
- JSON通信损坏了特殊字符
- 如何避免在Javascript中创建Json对象时使用特殊字符
- JSON分析因特殊字符而失败
- 在 Ajax POST 和 JSON 中发送特殊字符
- 从JSON到xml的特殊字符
- 如何添加具有特殊字符的字符串作为json键
- Js - json.解析-保留特殊字符
- JSON.用特殊字符解析
- JSON Javascript特殊字符如何获取值
- JSON中的特殊字符会破坏JS