我在JSON数组下面有这个如何删除键和值中的'\'。 [{\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\,\\\\\\\\\\\\\\\\\\\\\\, name \“:\” benefactor 1 \“”,“ \” objType \“:\” benefactor \“”,“ \” personId \“:\” person1 \“”,“ \” reference \“:\” \ “”,“ \”状态\“:1”,“ \” totalDonated \“:0”,“ \”水\“:0}”,“ {\” docType \“:\”钱包\“”,“ \“ id \”:\“ DW2 \”“,” \“ identity \”:\“钱包:benefactor:DW2 \”“,” \“ name \”:\“ benefactor 2 \”“,” \“ objType \“:\”受益人\“”,“ \” personId \“:\” person2 \“”,“ \”引用\“:\” \“”,“ \”状态\“:1”,“ \” totalDonated \“:0”,“ \” water \“:0}”,“ {\” docType \“:\”钱包\“”,“ \” id \“:\” DW3 \“”,“ \” identity \“:\” wallet:benefactor:DW3 \“”,“ \” name \“:\” benefactor 3 \“”,“ \” objType \“:\” benefactor \“”,“ \” personId \“ :\“ person3 \”“,” \“引用\”:\“ \”“,” \“状态\”:1“,” \“ totalDonated \”:0“,” \“水\”:0} “,” {\“ docType \”:\“钱包\”“,” \“ id \”:\“ DW4 \”“,” \“身份\”:\“钱包:受益人:DW4 \”“,” \“名称\”:\“受益人4 \”“,” \“ objType \”:\“受益人”“”,“ \” personId \“:\” person4 \“”,“ \”引用\“:\ “ \”“,” \“状态\”:1“,” \“ totalDonated \”:0“,” \“水\”:0}“,” {\“ docType \”:\“钱包\”“ ,“ \” id \“:\” DW5 \ “”,“ \” identity \“:\”钱包:benefactor:DW5 \“”,“ \”名称\“:\” benefactor 5 \“”,“ \” objType \“:\” benefactor \“”, “ \” personId \“:\” person5 \“”,“ \”引用\“:\” \“”,“ \”状态\“:1”,“ \” totalDonated \“:0”,“ \”水\“:0}]
答案 0 :(得分:0)
那不是JSON。此代码可以将字符串转换为列表。
<script>
function myFunction()
{
<!-- Manipulate the object width-->
}
</script>
<body>
<table>
<tr>
<td>
<!-- Any way to pass td object to Function()-->
<button onclick= "Function()">Test</button>
</td>
</tr>
</table>
</body>
# this is javascript code.
a = '[{\"docType\":\"wallet\"","\"id\":\"DW1\"","\"identity\":\"wallet:benefactor:DW1\"","\"name\":\"benefactor 1\"","\"objType\":\"benefactor\"","\"personId\":\"person1\"","\"reference\":\"\"","\"status\":1","\"totalDonated\":0","\"water\":0}","{\"docType\":\"wallet\"","\"id\":\"DW2\"","\"identity\":\"wallet:benefactor:DW2\"","\"name\":\"benefactor 2\"","\"objType\":\"benefactor\"","\"personId\":\"person2\"","\"reference\":\"\"","\"status\":1","\"totalDonated\":0","\"water\":0}","{\"docType\":\"wallet\"","\"id\":\"DW3\"","\"identity\":\"wallet:benefactor:DW3\"","\"name\":\"benefactor 3\"","\"objType\":\"benefactor\"","\"personId\":\"person3\"","\"reference\":\"\"","\"status\":1","\"totalDonated\":0","\"water\":0}","{\"docType\":\"wallet\"","\"id\":\"DW4\"","\"identity\":\"wallet:benefactor:DW4\"","\"name\":\"benefactor 4\"","\"objType\":\"benefactor\"","\"personId\":\"person4\"","\"reference\":\"\"","\"status\":1","\"totalDonated\":0","\"water\":0}","{\"docType\":\"wallet\"","\"id\":\"DW5\"","\"identity\":\"wallet:benefactor:DW5\"","\"name\":\"benefactor 5\"","\"objType\":\"benefactor\"","\"personId\":\"person5\"","\"reference\":\"\"","\"status\":1","\"totalDonated\":0","\"water\":0}]'
b = a.replace(/\",\"/g,",")
ret = JSON.parse(b)
# the ret is answer.
# python code.
import json, ast
# first, you have to add '' at your json data start and end.
a = '[{\"docType\":\"wallet\"","\"id\":\"DW1\"","\"identity\":\"wallet:benefactor:DW1\"","\"name\":\"benefactor 1\"","\"objType\":\"benefactor\"","\"personId\":\"person1\"","\"reference\":\"\"","\"status\":1","\"totalDonated\":0","\"water\":0}","{\"docType\":\"wallet\"","\"id\":\"DW2\"","\"identity\":\"wallet:benefactor:DW2\"","\"name\":\"benefactor 2\"","\"objType\":\"benefactor\"","\"personId\":\"person2\"","\"reference\":\"\"","\"status\":1","\"totalDonated\":0","\"water\":0}","{\"docType\":\"wallet\"","\"id\":\"DW3\"","\"identity\":\"wallet:benefactor:DW3\"","\"name\":\"benefactor 3\"","\"objType\":\"benefactor\"","\"personId\":\"person3\"","\"reference\":\"\"","\"status\":1","\"totalDonated\":0","\"water\":0}","{\"docType\":\"wallet\"","\"id\":\"DW4\"","\"identity\":\"wallet:benefactor:DW4\"","\"name\":\"benefactor 4\"","\"objType\":\"benefactor\"","\"personId\":\"person4\"","\"reference\":\"\"","\"status\":1","\"totalDonated\":0","\"water\":0}","{\"docType\":\"wallet\"","\"id\":\"DW5\"","\"identity\":\"wallet:benefactor:DW5\"","\"name\":\"benefactor 5\"","\"objType\":\"benefactor\"","\"personId\":\"person5\"","\"reference\":\"\"","\"status\":1","\"totalDonated\":0","\"water\":0}]'
m = a.replace('\\\"', '\"').replace("\",\"", ",")
m = ast.literal_eval(m)
print(m, type(m))
print(json.dumps(m))