Вот код для следующего выхода Json:
let params : [[String : AnyObject]] = [["name" : "action", "value" : "pay" ],["name" : "cartJsonData" , "value" : ["total": 1,"rows":[["quantity": "1" ,"title":"Donation for SMSF India - General Fund","price":"1","itemId":"DN001","cost": "1","currency":"INR"]]]], ["name" : "center", "value" : "Chennai"], ["name" : "flatNumber", "value" : "503"], ["name" : "panNumber", "value" : ""], ["name" : "payWith"], ["name" : "reminderFrequency","value" : "Monthly"], ["name" : "shipToAddr1"], ["name" : "shipToAddr2"], ["name" : "shipToCity"], ["name" : "shipToCountryName" , "value" : "India"], ["name" : "shipToEmail", "value" : "[email protected]"], ["name" : "shipToFirstName" , "value": "4480101010"], ["name" : "shipToLastName"], ["name" : "shipToPhone", "value" : "4480101010"], ["name" : "shipToState"], ["name" : "shipToZip"], ["name" : "userId", "value" : "null"], ["name" : "shipToCountry", "value" : "IN"]]
var jsonObject: NSData? = nil
do {
jsonObject = try NSJSONSerialization.dataWithJSONObject(params, options: NSJSONWritingOptions())
print(jsonObject) // This will print the below json.
}
catch{}
Распечатав jsonObject, я получил этот.
[{ "value" : "pay", "name" : "action" }, { "value" : { "rows": [{ "цена": "1" , "количество": "1" , "стоимость": "1" , "валюта": "INR", "itemId": "DN001", "title": "Пожертвование для SMSF India - Общий фонд" }], "total": 1}, "name" : "cartJsonData" }, { "value" : "Chennai", "name" : "center" }, { "value" : "503", "name" : "flatNumber" }, { "value" : "", "name" : "panNumber"}, { "name" : "payWith"}, { "value" : "Ежемесячно "," имя ":" reminderFrequency"}, { "name" : "shipToAddr1"}, { "name" : "shipToAddr2"}, { "name" : "shipToCity"}, { "value" : "India", "name" : "shipToCountryName"}, { "value" : "[email protected]", "name" : "shipToEmail"}, { "value" : "4480101010", "name" : "shipToFirstName"}, { "name" : "shipToLastName"}, { "value" : "4480101010", "name" : "shipToPhone"}, { "name" : "shipToState"}, { "name" : "shipToZip"}, { "value" : "null", "name" : "userId"}, { "value" : "IN", "name" : "shipToCountry"}]
И я хочу, чтобы JSON находился в следующем формате.
[{ "name" : "action", "value" : "pay" }, { "name" : "cartJsonData", " "стоимость": "{\ "total\": 1, \ "rows\": [{\ "itemId\": \ "DN002\", \ "title\": \ "Пожертвование для SMSF Индия - общий Фонд \" \ "количество \":\ "100 \",\ "валюта \":\ "INR \",\ "цена \":\ "1 \",\ "стоимость \": \ "100\" }]}" }, { "name" : "center", "value" : "Chennai" }, { "name" : "flatNumber", " "value" : ""}, { "name" : "panNumber", "value" : "ASSDDBBDJD"}, { "name" : "payWith"}, { "name" : "reminderFrequency", "value" : "Monthly" }, { "name" : "shipToAddr1"}, { "name" : "shipToAddr2"}, { "name" : "shipToCity"}, { "name" : "shipToCountryName", "value" : "India"}, { "name" : "shipToEmail", "value" : "[email protected]"}, { "name" : "shipToFirstName", "value" : "Raju"}, { "name" : "shipToLastName"}, { "name" : "shipToPhone", "value" : "1234567890"}, { "name" : "shipToState"}, { "name" : "shipToZip"}, { "name" : "userId", "value" : "null"}, { "name" : "shipToCountry", "value" : "IN"}]
Как это можно сделать? Необходимо изменить только значение в cartJsonData
. Может ли кто-нибудь помочь мне в этом, чтобы решить эту проблему?