Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
解析为json字符串的正确格式_Json_Swift - Fatal编程技术网

解析为json字符串的正确格式

解析为json字符串的正确格式,json,swift,Json,Swift,我试图将字典中的一个字符串传递给jsonstring,但它没有删除反斜杠,服务器也没有接受它。有什么想法吗 let myBod = "\"Body\": {" + "\"type\": \"multipart\"," + "\"content\": [" + "{" + "\"contentType\": \"multipart/alternative; Boundary=\\\"0__=4EBB0A76DFCD51048f9e8a

我试图将字典中的一个字符串传递给jsonstring,但它没有删除反斜杠,服务器也没有接受它。有什么想法吗

let myBod = "\"Body\": {" +
        "\"type\": \"multipart\"," +
        "\"content\": [" +
        "{" +
        "\"contentType\": \"multipart/alternative; Boundary=\\\"0__=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\\\"\"," +
        "\"contentDisposition\": \"inline\"" +
         " }," +
         "{" +
         "\"contentType\": \"text/plain; charset=US-ASCII\"," +
        "\"data\": \"yappy\"," +
         "\"boundary\": \"--0__=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\"" +
         " }," +
        " {" +
        "\"contentType\": \"text/html; charset=US-ASCII\"," +
          "\"contentDisposition\": \"inline\"," +
         "\"data\": \"<html><body>yappy</body></html>\"," +
         "\"boundary\": \"--0__=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\"}]}"
这将返回我的字符串,但不要消失反斜杠

JSON string = {"_Abstract":"Problema al instalar Historian 6.0 Enterprise  Info Link: https:\/\/soporte.adasoft.es\/browse\/NOVTRACERT-24","Executor":"","Watcher":[""],"Supervisor":"César Ramos","Name":"NOVTRACERT-24","Body":"{\"type\": \"multipart\",\"content\": [{\"contentType\": \"multipart\/alternative; Boundary=\\\"0__=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\\\"\",\"contentDisposition\": \"inline\" },{\"contentType\": \"text\/plain; charset=US-ASCII\",\"data\": \"Problema al instalar Historian 6.0 Enterprise\r\n\r\nInfo Link: https:\/\/soporte.adasoft.es\/browse\/NOVTRACERT-24\",\"boundary\": \"--0__=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\" }, {\"contentType\": \"text\/html; charset=US-ASCII\",\"contentDisposition\": \"inline\",\"data\": \"<html><body>Problema al instalar Historian 6.0 Enterprise\r\n\r\nInfo Link: https:\/\/soporte.adasoft.es\/browse\/NOVTRACERT-24<\/body><\/html>\",\"boundary\": \"--0__=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\"}]}"}
JSON string={“\u Abstract”:“Problema al-instalar Historian 6.0企业信息链接:https:\/\/soport.adasoft.es\/browse\/NOVTRACERT-24”,“Executor:”,“Watcher:[”,“Supervisor:”,“Supervisor:“César Ramos”,“Name:“NOVTRACERT-24”,“Body:”,“{\“type\”:“multipart\”,“content\”:[{\“contentType\”:“multipart\/”可选;边界=\\\“0\\=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\\\”,“内容配置\\”:\“内联\\”,{\“内容类型\\”:\“文本\/plain;字符集=US-ASCII\”,“数据\\:\“问题不稳定历史记录6.0企业\r\n\r\n信息链接:https:\/\/soporte.adasoft.es\/浏览\/novt-24\,“边界\”:\“--0\\\\\=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\”,{“contentType\”:“text\/html;charset=US-ASCII\”,“contentDisposition\”:“inline\”,“data\”:“Problema al-Installar Historian 6.0 Enterprise\r\n\r\n信息链接:https:\/\/soport.adasoft.es\/browse\/NOVTRACERT-24\,“boundary\”:”--0_uu=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\'}]}

我猜这就是您看到的输出:

{
    "_Abstract": "Problema al instalar Historian 6.0 Enterprise  Info Link: https:\/\/soporte.adasoft.es\/browse\/NOVTRACERT-24",
    "Executor": "",
    "Watcher": [""],
    "Supervisor": "César Ramos",
    "Name": "NOVTRACERT-24",
    "Body": "{\"type\": \"multipart\",\"content\": [{\"contentType\": \"multipart\/alternative; Boundary=\\\"0__=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\\\"\",\"contentDisposition\": \"inline\" },{\"contentType\": \"text\/plain; charset=US-ASCII\",\"data\": \"Problema al instalar Historian 6.0 Enterprise\r\n\r\nInfo Link: https:\/\/soporte.adasoft.es\/browse\/NOVTRACERT-24\",\"boundary\": \"--0__=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\" }, {\"contentType\": \"text\/html; charset=US-ASCII\",\"contentDisposition\": \"inline\",\"data\": \"<html><body>Problema al instalar Historian 6.0 Enterprise\r\n\r\nInfo Link: https:\/\/soporte.adasoft.es\/browse\/NOVTRACERT-24<\/body><\/html>\",\"boundary\": \"--0__=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\"}]}"
}
{
“\u摘要”:“Problema al-instalar Historian 6.0企业信息链接:https:\/\/soport.adasoft.es\/browse\/NOVTRACERT-24”,
“遗嘱执行人”:“,
“观察者”:[“”],
“主管”:“César Ramos”,
“名称”:“NOVTRACERT-24”,
“正文”:“{”类型\“:\”多部分\“,\”内容\“:[{”内容类型\“:\”多部分\/alternative;边界=\\\\\”0\\\\\\\\\\\\=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\\”,\“内容处置\\”:“内联\“,{”内容类型\:“文本\/plain;字符集=US-ASCII\,“数据\\:”Problema al Installar Historian 6.0 Enterprise\r\n\r\n信息链接:https:\/\/soport.adasoft.es\/browse\/NOVTRACERT-24\,“boundary\”:“--0\=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\”,{\“contentType\”:“text\/html;charset=US-ASCII\,“contentDisposition\”:“inline\”,“data\:”Problema al Installar Historian 6.0 Enterprise\r\n\r\n信息链接:https:\/\/soport.adasoft.es\/browse\/NOVTRACERT-24\,“boundary\:\“--0\=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\”}”
}
我运行它来美化它,并检查它是否有效。
正文
项是一个包含JSON的字符串(在本例中),但由于它在另一段JSON中被序列化为字符串,所有JSON特殊字符都需要转义(即
\
)。这是您要求的,并且编码正确


如果您希望
body
是JSON对象而不是字符串,则需要首先通过反序列化将其转换为JSON,然后设置
body
键,然后序列化整个消息。

Show.Your.code。字符串中的反斜杠是虚拟的。它们会转义双引号以避免破坏字符串representation。正如@vadian所说,展示代码,以及你期望看到的和正在看到的。编辑帖子,有什么想法吗?你没有按照我的要求去做。
dataToPost
myBod
有什么关系?当我说“展示你正在看到的”时,我不是指发布另一个作业声明,显示打印语句的输出。dataPost等于myBod
{
    "_Abstract": "Problema al instalar Historian 6.0 Enterprise  Info Link: https:\/\/soporte.adasoft.es\/browse\/NOVTRACERT-24",
    "Executor": "",
    "Watcher": [""],
    "Supervisor": "César Ramos",
    "Name": "NOVTRACERT-24",
    "Body": "{\"type\": \"multipart\",\"content\": [{\"contentType\": \"multipart\/alternative; Boundary=\\\"0__=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\\\"\",\"contentDisposition\": \"inline\" },{\"contentType\": \"text\/plain; charset=US-ASCII\",\"data\": \"Problema al instalar Historian 6.0 Enterprise\r\n\r\nInfo Link: https:\/\/soporte.adasoft.es\/browse\/NOVTRACERT-24\",\"boundary\": \"--0__=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\" }, {\"contentType\": \"text\/html; charset=US-ASCII\",\"contentDisposition\": \"inline\",\"data\": \"<html><body>Problema al instalar Historian 6.0 Enterprise\r\n\r\nInfo Link: https:\/\/soporte.adasoft.es\/browse\/NOVTRACERT-24<\/body><\/html>\",\"boundary\": \"--0__=4EBB0A76DFCD51048f9e8a93df938690918c4EBB0A76DFCD5104\"}]}"
}