我正在尝试为JSON POST请求生成参数, 这是我要实现的目标:
{
"Associate_Name": "SAURABH K WATT",
"Associate_Code": "DT1006",
"Transaction_No": "6",
"TRANSACTION_MODE": "2",
"COMPANY_NO": "cogni",
"LOCATION_NO": "NOIDA",
"REPORTING_DATE": "2019-07-09",
"SERVER_DATE": "2019-07-11",
"ItemDtail": [
{
"LI_NO": "1",
"CUSTOMER_ID": "C103",
"PROJECT_ID": "IMSGTPL0052",
"Activity_Id": "DEVELOPMEN",
"ACTIVITY": "DEVELOPMEN",
"ACTIVITY_DETAILS": "test",
"TOTAL_HOURS": "1.30",
"PERCENTAGE": "16.25",
"STATUS": "2",
"REMARKS1": "",
"REMARKS2": "",
"REMARKS3": "",
"user_id": "62",
"Doc_Status": "F",
"ConvertedTime": "1.30",
"CaseId": "0"
},
{
"LI_NO": "2",
"CUSTOMER_ID": "C103",
"PROJECT_ID": "PROJ1029",
"Activity_Id": "DEV2",
"ACTIVITY": "DEV2",
"ACTIVITY_DETAILS": "sat",
"TOTAL_HOURS": "6.30",
"PERCENTAGE": "78.75",
"STATUS": "1",
"REMARKS1": "",
"REMARKS2": "",
"REMARKS3": "",
"user_id": "62",
"Doc_Status": "F",
"ConvertedTime": "6.30",
"CaseId": "0"
}
]
}
到目前为止,我已经这样尝试过:
let param : [String:Any] = [
"Associate_Name": "SAURABH K WATT",
"Associate_Code": "DT1006",
"Transaction_No": "13",
"TRANSACTION_MODE": "1",
"COMPANY_NO": "cogni",
"LOCATION_NO": "NOIDA",
"REPORTING_DATE": "2019-07-05",
"SERVER_DATE": "2019-07-11",
"ItemDtail": [
[
"LI_NO": "1",
"CUSTOMER_ID": "C103",
"PROJECT_ID": "IMSGTPL0052",
"Activity_Id": "DEVELOPMEN",
"ACTIVITY": "DEVELOPMEN",
"ACTIVITY_DETAILS": "test",
"TOTAL_HOURS": "1.30",
"PERCENTAGE": "16.25",
"STATUS": "2",
"REMARKS1": "",
"REMARKS2": "",
"REMARKS3": "",
"user_id": "62",
"Doc_Status": "F",
"ConvertedTime": "1.30",
"CaseId": "0"
]
]
]
但是从这种存储方式来看,我得到了错误的JSON序列,最终的JSON打印如下:
JSON string =
{
"Transaction_No" : "13",
"TRANSACTION_MODE" : "1",
"COMPANY_NO" : "cogni",
"SERVER_DATE" : "2019-07-11",
"Associate_Code" : "DT1006",
"ItemDtail" : [
{
"TOTAL_HOURS" : "1.30",
"ACTIVITY" : "DEVELOPMEN",
"ConvertedTime" : "1.30",
"CUSTOMER_ID" : "C103",
"Activity_Id" : "DEVELOPMEN",
"PERCENTAGE" : "16.25",
"REMARKS1" : "",
"REMARKS3" : "",
"ACTIVITY_DETAILS" : "test",
"user_id" : "62",
"CaseId" : "0",
"STATUS" : "2",
"LI_NO" : "1",
"PROJECT_ID" : "IMSGTPL0052",
"Doc_Status" : "F",
"REMARKS2" : ""
}
],
"REPORTING_DATE" : "2019-07-05",
"LOCATION_NO" : "NOIDA",
"Associate_Name" : "SAURABH K WATT"
}
这是错误的。请帮忙,我到处搜索过但没有找到任何解决方案,我在过去三天中一直陷入困境。