gpt4 book ai didi

json - 为什么我的 json 格式的字符串没有通过在 swift 3 中使用 swiftyjson 库转换为 json 数组

转载 作者:行者123 更新时间:2023-11-28 08:20:23 25 4
gpt4 key购买 nike

我正在尝试使用 ios 中的 swift json 将作为字符串响应从服务器获取的以下字符串转换为 json 数组。但它没有被转换成字符串。

这是我的字符串:

[{\"Sno\":\"1\",\"Grivence_Code\":\"5511\",\"CaseType\":\"ACP\",\"MarkedTo\":\"DGSE\",\"Applied_Date\":\"09-Jun-2016\",\"Description\":\"hahahha\",\"CurrentStatus\":\"Disposed Off\",\"Action_Code\":\"6290\",\"Action_TakenBy\":\"DGSE\",\"Action_Date\":\"28-Jun-2016\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740688052\"},{\"Sno\":\"2\",\"Grivence_Code\":\"5516\",\"CaseType\":\"ACP\",\"MarkedTo\":\"DGSE\",\"Applied_Date\":\"09-Jun-2016\",\"Description\":\"\n\n\n\n\n\n\",\"CurrentStatus\":\"Disposed Off\",\"Action_Code\":\"6290\",\"Action_TakenBy\":\"DGSE\",\"Action_Date\":\"28-Jun-2016\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740674400\"},{\"Sno\":\"3\",\"Grivence_Code\":\"5522\",\"CaseType\":\"ACP\",\"MarkedTo\":\"DGSE\",\"Applied_Date\":\"12-Jun-2016\",\"Description\":\"testing testing testing testing testing testing \",\"CurrentStatus\":\"Disposed Off\",\"Action_Code\":\"6290\",\"Action_TakenBy\":\"DGSE\",\"Action_Date\":\"28-Jun-2016\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740663938\"},{\"Sno\":\"4\",\"Grivence_Code\":\"5529\",\"CaseType\":\"ACP\",\"MarkedTo\":\"CEO(Nabha)\",\"Applied_Date\":\"13-Jun-2016\",\"Description\":\"testing. \",\"CurrentStatus\":\"Pending\",\"Action_Code\":\"\",\"Action_TakenBy\":\"CEO(Nabha)\",\"Action_Date\":\"\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740659500\"},{\"Sno\":\"5\",\"Grivence_Code\":\"5530\",\"CaseType\":\"ACP\",\"MarkedTo\":\"DGSE\",\"Applied_Date\":\"13-Jun-2016\",\"Description\":\"bbbnnnnnnbbbvvvvvvbbbbvbbbb\",\"CurrentStatus\":\"Disposed Off\",\"Action_Code\":\"6290\",\"Action_TakenBy\":\"DGSE\",\"Action_Date\":\"28-Jun-2016\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740647081\"},{\"Sno\":\"6\",\"Grivence_Code\":\"5531\",\"CaseType\":\"ACP\",\"MarkedTo\":\"DGSE\",\"Applied_Date\":\"13-Jun-2016\",\"Description\":\" vvbhhhhhhhhhhgvg. vvbhhhhhhhhhhgvg. \",\"CurrentStatus\":\"Disposed Off\",\"Action_Code\":\"6290\",\"Action_TakenBy\":\"DGSE\",\"Action_Date\":\"28-Jun-2016\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740634790\"},{\"Sno\":\"7\",\"Grivence_Code\":\"5532\",\"CaseType\":\"ACP\",\"MarkedTo\":\"DGSE\",\"Applied_Date\":\"13-Jun-2016\",\"Description\":\"I m in prakshvtadavhjhgggggggggggghggghhhg\",\"CurrentStatus\":\"Disposed Off\",\"Action_Code\":\"6290\",\"Action_TakenBy\":\"DGSE\",\"Action_Date\":\"28-Jun-2016\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740678909\"},{\"Sno\":\"8\",\"Grivence_Code\":\"5728\",\"CaseType\":\"Increment related\",\"MarkedTo\":\"CEO(Jalandhar)\",\"Applied_Date\":\"01-Aug-2016\",\"Description\":\"rigorous testing is the most mandatory step towards developing robust software \",\"CurrentStatus\":\"Disposed Off\",\"Action_Code\":\"6718\",\"Action_TakenBy\":\"CEO(Jalandhar)\",\"Action_Date\":\"12-Aug-2016\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740611379\"},{\"Sno\":\"9\",\"Grivence_Code\":\"5884\",\"CaseType\":\"ACP\",\"MarkedTo\":\"DGSE\",\"Applied_Date\":\"10-Sep-2016\",\"Description\":\"hellovvnnbvccccdccxxxccccccvv\",\"CurrentStatus\":\"Disposed Off\",\"Action_Code\":\"6290\",\"Action_TakenBy\":\"DGSE\",\"Action_Date\":\"12-Sep-2016\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740697305\"},{\"Sno\":\"10\",\"Grivence_Code\":\"5885\",\"CaseType\":\"Probation Period related\",\"MarkedTo\":\"Director (SCERT)\",\"Applied_Date\":\"10-Sep-2016\",\"Description\":\"vgccgggcgggggvbvvhbbvvbbbbbbbb\",\"CurrentStatus\":\"Pending\",\"Action_Code\":\"\",\"Action_TakenBy\":\"Director (SCERT)\",\"Action_Date\":\"\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740686213\"},{\"Sno\":\"11\",\"Grivence_Code\":\"6176\",\"CaseType\":\"ACR\",\"MarkedTo\":\"DEO(EE)-BATHINDA\",\"Applied_Date\":\"05-Jan-2017\",\"Description\":\"Addedczxvxvxvdzvdgdsdgdsxgdgdsgdfgdsgdss\",\"CurrentStatus\":\"Pending\",\"Action_Code\":\"\",\"Action_TakenBy\":\"DEO(EE)-BATHINDA\",\"Action_Date\":\"\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740618188\"}]

这是我的代码:

if let dataFromString = string.data(using: .utf8, allowLossyConversion: false) {

let json = JSON(data: dataFromString)
var i=0

for i in 0..<json.count {

}
}

它总是给 json 计数 0。请帮助。

最佳答案

let swiftyJsonVar = "[{\"Sno\":\"1\",\"Grivence_Code\":\"5511\",\"CaseType\":\"ACP\",\"MarkedTo\":\"DGSE\",\"Applied_Date\":\"09-Jun-2016\",\"Description\":\"hahahha\",\"CurrentStatus\":\"Disposed Off\",\"Action_Code\":\"6290\",\"Action_TakenBy\":\"DGSE\",\"Action_Date\":\"28-Jun-2016\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740688052\"},{\"Sno\":\"2\",\"Grivence_Code\":\"5516\",\"CaseType\":\"ACP\",\"MarkedTo\":\"DGSE\",\"Applied_Date\":\"09-Jun-2016\",\"Description\":\"\",\"CurrentStatus\":\"Disposed Off\",\"Action_Code\":\"6290\",\"Action_TakenBy\":\"DGSE\",\"Action_Date\":\"28-Jun-2016\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740674400\"},{\"Sno\":\"3\",\"Grivence_Code\":\"5522\",\"CaseType\":\"ACP\",\"MarkedTo\":\"DGSE\",\"Applied_Date\":\"12-Jun-2016\",\"Description\":\"testing testing testing testing testing testing \",\"CurrentStatus\":\"Disposed Off\",\"Action_Code\":\"6290\",\"Action_TakenBy\":\"DGSE\",\"Action_Date\":\"28-Jun-2016\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740663938\"},{\"Sno\":\"4\",\"Grivence_Code\":\"5529\",\"CaseType\":\"ACP\",\"MarkedTo\":\"CEO(Nabha)\",\"Applied_Date\":\"13-Jun-2016\",\"Description\":\"testing. \",\"CurrentStatus\":\"Pending\",\"Action_Code\":\"\",\"Action_TakenBy\":\"CEO(Nabha)\",\"Action_Date\":\"\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740659500\"},{\"Sno\":\"5\",\"Grivence_Code\":\"5530\",\"CaseType\":\"ACP\",\"MarkedTo\":\"DGSE\",\"Applied_Date\":\"13-Jun-2016\",\"Description\":\"bbbnnnnnnbbbvvvvvvbbbbvbbbb\",\"CurrentStatus\":\"Disposed Off\",\"Action_Code\":\"6290\",\"Action_TakenBy\":\"DGSE\",\"Action_Date\":\"28-Jun-2016\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740647081\"},{\"Sno\":\"6\",\"Grivence_Code\":\"5531\",\"CaseType\":\"ACP\",\"MarkedTo\":\"DGSE\",\"Applied_Date\":\"13-Jun-2016\",\"Description\":\" vvbhhhhhhhhhhgvg. vvbhhhhhhhhhhgvg. \",\"CurrentStatus\":\"Disposed Off\",\"Action_Code\":\"6290\",\"Action_TakenBy\":\"DGSE\",\"Action_Date\":\"28-Jun-2016\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740634790\"},{\"Sno\":\"7\",\"Grivence_Code\":\"5532\",\"CaseType\":\"ACP\",\"MarkedTo\":\"DGSE\",\"Applied_Date\":\"13-Jun-2016\",\"Description\":\"I m in prakshvtadavhjhgggggggggggghggghhhg\",\"CurrentStatus\":\"Disposed Off\",\"Action_Code\":\"6290\",\"Action_TakenBy\":\"DGSE\",\"Action_Date\":\"28-Jun-2016\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740678909\"},{\"Sno\":\"8\",\"Grivence_Code\":\"5728\",\"CaseType\":\"Increment related\",\"MarkedTo\":\"CEO(Jalandhar)\",\"Applied_Date\":\"01-Aug-2016\",\"Description\":\"rigorous testing is the most mandatory step towards developing robust software \",\"CurrentStatus\":\"Disposed Off\",\"Action_Code\":\"6718\",\"Action_TakenBy\":\"CEO(Jalandhar)\",\"Action_Date\":\"12-Aug-2016\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740611379\"},{\"Sno\":\"9\",\"Grivence_Code\":\"5884\",\"CaseType\":\"ACP\",\"MarkedTo\":\"DGSE\",\"Applied_Date\":\"10-Sep-2016\",\"Description\":\"hellovvnnbvccccdccxxxccccccvv\",\"CurrentStatus\":\"Disposed Off\",\"Action_Code\":\"6290\",\"Action_TakenBy\":\"DGSE\",\"Action_Date\":\"12-Sep-2016\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740697305\"},{\"Sno\":\"10\",\"Grivence_Code\":\"5885\",\"CaseType\":\"Probation Period related\",\"MarkedTo\":\"Director (SCERT)\",\"Applied_Date\":\"10-Sep-2016\",\"Description\":\"vgccgggcgggggvbvvhbbvvbbbbbbbb\",\"CurrentStatus\":\"Pending\",\"Action_Code\":\"\",\"Action_TakenBy\":\"Director (SCERT)\",\"Action_Date\":\"\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740686213\"},{\"Sno\":\"11\",\"Grivence_Code\":\"6176\",\"CaseType\":\"ACR\",\"MarkedTo\":\"DEO(EE)-BATHINDA\",\"Applied_Date\":\"05-Jan-2017\",\"Description\":\"Addedczxvxvxvdzvdgdsdgdsxgdgdsgdfgdsgdss\",\"CurrentStatus\":\"Pending\",\"Action_Code\":\"\",\"Action_TakenBy\":\"DEO(EE)-BATHINDA\",\"Action_Date\":\"\",\"Remarks\":\"\",\"FacultyInfo_Code\":\"107406\",\"GrievanceNumber\":\"10740618188\"}]"
let finalJSON = JSON.parse(swiftyJsonVar)

print(finalJSON.arrayObject);
// you can use any of this to get your desired object
//print(finalJSON.arrayValue);
//print(finalJSON.array);

[ Result]

关于json - 为什么我的 json 格式的字符串没有通过在 swift 3 中使用 swiftyjson 库转换为 json 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41500313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com