- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好的。陷入简单的任务,将项目从 AFNetworking swift 2 转换为 Alamofire swift 3。
我有一个 json 对象 (SwiftyJSON),需要作为正文 json 参数发送。
这是我的对象:
{
"enableSMS" : 1,
"deviceAssociationID" : 12,
"timeStamp" : "2016-10-07 23:35:32",
"userDeviceAccessID" : 1,
"valueBattery" : 25,
"deviceDescription" : "<null>",
"deviceID" : 1,
"valueTemperature" : 46,
"valueTRange1" : "0.000000",
"deviceTypeId" : 1,
"latitude" : "-23.504236000000000",
"enableEmail" : 1,
"valueTiers" : [
{
"userShareDeviceId" : 6,
"sharedStatusId" : 1,
"sharedStatus" : "INVITE_SENT",
"destUserId" : 60,
"personEmail" : "eu@you.com",
"sharedDate" : "2016-08-17 20:57:06",
"personName" : "Daniel",
"personPhone" : "+55 11 9999999999",
"acceptationDate" : null
},
{
"userShareDeviceId" : 7,
"sharedStatusId" : 1,
"sharedStatus" : "INVITE_SENT",
"destUserId" : 1,
"personEmail" : "x@y.com",
"sharedDate" : "2016-10-04 20:00:06",
"personName" : "John",
"personPhone" : "",
"acceptationDate" : null
}
],
"enableTimeRange" : 1,
"deviceVersion" : "0.1",
"valueSMS" : [
{
"SMSId" : 1,
"personName" : "Daniel",
"personPhone" : "+55 11 999999999"
}
],
"deviceName" : "Vovózinhaaaa",
"jsonAddress" : "{\"place_id\":\"24020287\",\"licence\":\"Data © OpenStreetMap contributors, ODbL 1.0. http:\\\/\\\/www.openstreetmap.org\\\/copyright\",\"osm_type\":\"node\",\"osm_id\":\"2355070909\",\"lat\":\"-23.5038297\",\"lon\":\"-46.6285165\",\"display_name\":\"Itaú Personalité, Avenida Brás Leme, Jardim São Bento, Casa Verde, SP, Microrregião de São Paulo, RMSP, Mesorregião Metropolitana de São Paulo, SP, Região Sudeste, 02022-010, Brasil\",\"address\":{\"bank\":\"Itaú Personalité\",\"road\":\"Avenida Brás Leme\",\"neighbourhood\":\"Jardim São Bento\",\"suburb\":\"Casa Verde\",\"city_district\":\"Casa Verde\",\"city\":\"SP\",\"county\":\"Microrregião de São Paulo\",\"state_district\":\"Mesorregião Metropolitana de São Paulo\",\"state\":\"SP\",\"postcode\":\"02022-010\",\"country\":\"Brasil\",\"country_code\":\"br\"},\"boundingbox\":[\"-23.5039297\",\"-23.5037297\",\"-46.6286165\",\"-46.6284165\"]}",
"deviceJSONWeather" : "{\"coord\":{\"lon\":-46.63,\"lat\":-23.47},\"weather\":[{\"id\":802,\"main\":\"Clouds\",\"description\":\"scattered clouds\",\"icon\":\"03n\"}],\"base\":\"cmc stations\",\"main\":{\"temp\":299.26,\"pressure\":1023,\"humidity\":81,\"temp_min\":299.26,\"temp_max\":299.26},\"wind\":{\"speed\":3.08,\"deg\":70,\"gust\":3.08},\"rain\":{\"3h\":0.03},\"clouds\":{\"all\":36},\"dt\":1470863106,\"sys\":{\"type\":3,\"id\":135121,\"message\":0.0091,\"country\":\"BR\",\"sunrise\":1470821690,\"sunset\":1470862123},\"id\":3467431,\"name\":\"Cantareira\",\"cod\":200}",
"acceleration" : "3.89743600",
"temperature" : "27.00",
"speed" : "9.000000",
"valueEmails" : [
{
"emailId" : 1,
"personName" : "John Doe",
"personEmail" : "j@doe.com"
},
{
"emailId" : 2,
"personName" : "Daniel",
"personEmail" : "eu@you.com"
}
],
"longitude" : "-46.628792000000000",
"valueGeoFencing" : [
{
"geoFencingAnalyseSaturday" : 1,
"geoFencingLongitude" : "-46.639857300000020",
"geoFencingName" : "Geo 1",
"geoFencingAddress" : "Tv. Heliodora, 14",
"geoFencingLatitude" : "-23.503186700000000",
"geoFencingTimeRange1" : "0.150000000",
"geoFencingAnalyseSunday" : 0,
"geoFencingTimeEnabled" : 0,
"geoFencingAnalyseMonday" : 1,
"geoFencingAnalyseTuesday" : 1,
"geoFencingTypeId" : 1,
"geoFencingTimeRange2" : "0.750000000",
"geoFencingId" : 5,
"geoFencingAnalyseFriday" : 1,
"geoFencingRadius" : 744,
"geoFencingAnalyseWednesday" : 0,
"geoFencingTypeName" : "ENTER",
"geoFencingAnalyseThursday" : 1
}
],
"enableImpact" : 1,
"enableGeoFencing" : 1,
"devicePicture" : "https:\/\/pic.com\/devices\/12.jpg",
"userID" : 1,
"enableAlerts" : 1,
"useTypeDescription" : "SENIOR",
"enableBattery" : 1,
"valueSpeed" : 62,
"batteryLevel" : 73,
"valueTRange2" : "1.000000",
"altitude" : "721.900024",
"enableSpeed" : 1,
"deviceTimeZoneName" : "(GMT -3:00) Eastern Brazil",
"heading_to" : "116.839996",
"enableTemperature" : 1,
"enableTiers" : 1,
"deviceStatus" : "ACTIVATED",
"deviceSerialNumber" : "TRX00001",
"alertsNonRead" : 69,
"deviceUseTypeId" : 4,
"deviceTimeZone" : "America\/Sao_Paulo"
}
尝试直接发布它(转换为参数类型),我的 API 无法识别任何参数。
然后我转换为字典:
do {
let dic = try JSONSerialization.jsonObject(with: data!, options: .allowFragments)
userDevices.updateUserDevices(settings: dic as! Parameters) { (response, error) in
print(response)
print(error)
}
} catch {
print("error")
}
调试 Alamofire 后我有这个序列化:
"{\"enableSMS\":1,\"deviceAssociationID\":12,\"deviceTimeZone\":\"America\/Sao_Paulo\",\"userDeviceAccessID\":1,\"valueBattery\":25,\"deviceDescription\":\"<null>\",\"deviceID\":1,\"valueTemperature\":46,\"valueTRange1\":\"0.000000\",\"deviceTypeId\":1,\"latitude\":\"-23.504236000000000\",\"enableEmail\":1,\"valueTiers\":[{\"userShareDeviceId\":6,\"sharedStatusId\":1,\"sharedStatus\":\"INVITE_SENT\",\"destUserId\":60,\"personEmail\":\"eu@daniellombardi.com.br\",\"sharedDate\":\"2016-08-17 20:57:06\",\"personName\":\"Daniel Lombardi\",\"personPhone\":\"+55 11 981378213\",\"acceptationDate\":null},{\"userShareDeviceId\":7,\"sharedStatusId\":1,\"sharedStatus\":\"INVITE_SENT\",\"destUserId\":1,\"personEmail\":\"giulio@loffreda.com.br\",\"sharedDate\":\"2016-10-04 20:00:06\",\"personName\":\"Giulio\",\"personPhone\":\"\",\"acceptationDate\":null}],\"enableTimeRange\":1,\"deviceVersion\":\"0.1\",\"valueSMS\":[{\"SMSId\":1,\"personName\":\"Daniel Lombardi\",\"personPhone\":\"+55 11 981378213\"}],\"deviceName\":\"Vovózinhaaaa\",\"userID\":1,\"deviceJSONWeather\":\"{\\\"coord\\\":{\\\"lon\\\":-46.63,\\\"lat\\\":-23.47},\\\"weather\\\":[{\\\"id\\\":802,\\\"main\\\":\\\"Clouds\\\",\\\"description\\\":\\\"scattered clouds\\\",\\\"icon\\\":\\\"03n\\\"}],\\\"base\\\":\\\"cmc stations\\\",\\\"main\\\":{\\\"temp\\\":299.26,\\\"pressure\\\":1023,\\\"humidity\\\":81,\\\"temp_min\\\":299.26,\\\"temp_max\\\":299.26},\\\"wind\\\":{\\\"speed\\\":3.08,\\\"deg\\\":70,\\\"gust\\\":3.08},\\\"rain\\\":{\\\"3h\\\":0.03},\\\"clouds\\\":{\\\"all\\\":36},\\\"dt\\\":1470863106,\\\"sys\\\":{\\\"type\\\":3,\\\"id\\\":135121,\\\"message\\\":0.0091,\\\"country\\\":\\\"BR\\\",\\\"sunrise\\\":1470821690,\\\"sunset\\\":1470862123},\\\"id\\\":3467431,\\\"name\\\":\\\"Cantareira\\\",\\\"cod\\\":200}\",\"jsonAddress\":\"{\\\"place_id\\\":\\\"24020287\\\",\\\"licence\\\":\\\"Data © OpenStreetMap contributors, ODbL 1.0. http:\\\/\\\/www.openstreetmap.org\\\/copyright\\\",\\\"osm_type\\\":\\\"node\\\",\\\"osm_id\\\":\\\"2355070909\\\",\\\"lat\\\":\\\"-23.5038297\\\",\\\"lon\\\":\\\"-46.6285165\\\",\\\"display_name\\\":\\\"Itaú Personalité, Avenida Brás Leme, Jardim São Bento, Casa Verde, SP, Microrregião de São Paulo, RMSP, Mesorregião Metropolitana de São Paulo, SP, Região Sudeste, 02022-010, Brasil\\\",\\\"address\\\":{\\\"bank\\\":\\\"Itaú Personalité\\\",\\\"road\\\":\\\"Avenida Brás Leme\\\",\\\"neighbourhood\\\":\\\"Jardim São Bento\\\",\\\"suburb\\\":\\\"Casa Verde\\\",\\\"city_district\\\":\\\"Casa Verde\\\",\\\"city\\\":\\\"SP\\\",\\\"county\\\":\\\"Microrregião de São Paulo\\\",\\\"state_district\\\":\\\"Mesorregião Metropolitana de São Paulo\\\",\\\"state\\\":\\\"SP\\\",\\\"postcode\\\":\\\"02022-010\\\",\\\"country\\\":\\\"Brasil\\\",\\\"country_code\\\":\\\"br\\\"},\\\"boundingbox\\\":[\\\"-23.5039297\\\",\\\"-23.5037297\\\",\\\"-46.6286165\\\",\\\"-46.6284165\\\"]}\",\"temperature\":\"27.00\",\"speed\":\"9.000000\",\"valueEmails\":[{\"emailId\":1,\"personName\":\"Giulio Loffreda\",\"personEmail\":\"giulio@loffreda.com.br\"},{\"emailId\":2,\"personName\":\"Daniel Lombardi\",\"personEmail\":\"eu@daniellombardi.com.br\"}],\"longitude\":\"-46.628792000000000\",\"valueGeoFencing\":[{\"geoFencingAnalyseThursday\":1,\"geoFencingLongitude\":\"-46.639857300000020\",\"geoFencingName\":\"Geo 1\",\"geoFencingAddress\":\"Tv. Heliodora, 14\",\"geoFencingLatitude\":\"-23.503186700000000\",\"geoFencingTimeRange1\":\"0.150000000\",\"geoFencingAnalyseSunday\":0,\"geoFencingTimeEnabled\":0,\"geoFencingAnalyseMonday\":1,\"geoFencingAnalyseTuesday\":1,\"geoFencingTypeId\":1,\"geoFencingTimeRange2\":\"0.750000000\",\"geoFencingId\":5,\"geoFencingAnalyseFriday\":1,\"geoFencingRadius\":744,\"geoFencingAnalyseSaturday\":1,\"geoFencingAnalyseWednesday\":0,\"geoFencingTypeName\":\"ENTER\"}],\"enableImpact\":1,\"enableGeoFencing\":1,\"devicePicture\":\"https:\/\/profiles.t-rex.io\/devices\/12.jpg\",\"acceleration\":\"3.89743600\",\"enableAlerts\":1,\"useTypeDescription\":\"SENIOR\",\"enableBattery\":1,\"valueSpeed\":62,\"batteryLevel\":73,\"valueTRange2\":\"1.000000\",\"altitude\":\"721.900024\",\"enableSpeed\":1,\"deviceTimeZoneName\":\"(GMT -3:00) Eastern Brazil\",\"heading_to\":\"116.839996\",\"enableTemperature\":1,\"enableTiers\":1,\"deviceStatus\":\"ACTIVATED\",\"deviceSerialNumber\":\"TRX00001\",\"alertsNonRead\":69,\"deviceUseTypeId\":4,\"timeStamp\":\"2016-10-07 23:35:32\"}" \
这不符合 json 或 api。
这是我的电话:
alamoFireManager?.request("\(urlUserApi)\", method: .post, parameters: settings, encoding: JSONEncoding.default, headers:["Authorization" : userData.apiKey])
.debugLog()
.responseJSON(completionHandler: { (response) in
switch response.result {
case .success:
let useType = JSON(response.result.value!)
if ((useType["error"].bool) == true) {
let error = NSError(domain: UserErrorDomain, code: -982, userInfo: [NSLocalizedDescriptionKey: translateStrings(useType["message"].string!)])
completion(nil, error)
} else {
completion(useType, nil)
}
case .failure(let error):
completion(nil, error)
}
})
尝试使用 URLEncoding.default 更改编码(尝试了所有这些)我有这个:
"acceleration=3.89743600&alertsNonRead=69&altitude=721.900024&batteryLevel=73&deviceAssociationID=12&deviceDescription=%3Cnull%3E&deviceID=1&deviceJSONWeather=%7B%22coord%22%3A%7B%22lon%22%3A-46.63%2C%22lat%22%3A-23.47%7D%2C%22weather%22%3A%5B%7B%22id%22%3A802%2C%22main%22%3A%22Clouds%22%2C%22description%22%3A%22scattered%20clouds%22%2C%22icon%22%3A%2203n%22%7D%5D%2C%22base%22%3A%22cmc%20stations%22%2C%22main%22%3A%7B%22temp%22%3A299.26%2C%22pressure%22%3A1023%2C%22humidity%22%3A81%2C%22temp_min%22%3A299.26%2C%22temp_max%22%3A299.26%7D%2C%22wind%22%3A%7B%22speed%22%3A3.08%2C%22deg%22%3A70%2C%22gust%22%3A3.08%7D%2C%22rain%22%3A%7B%223h%22%3A0.03%7D%2C%22clouds%22%3A%7B%22all%22%3A36%7D%2C%22dt%22%3A1470863106%2C%22sys%22%3A%7B%22type%22%3A3%2C%22id%22%3A135121%2C%22message%22%3A0.0091%2C%22country%22%3A%22BR%22%2C%22sunrise%22%3A1470821690%2C%22sunset%22%3A1470862123%7D%2C%22id%22%3A3467431%2C%22name%22%3A%22Cantareira%22%2C%22cod%22%3A200%7D&deviceName=Vov%C3%B3zinhaaaa&devicePicture=https%3A//profiles.t-rex.io/devices/12.jpg&deviceSerialNumber=TRX00001&deviceStatus=ACTIVATED&deviceTimeZone=America/Sao_Paulo&deviceTimeZoneName=%28GMT%20-3%3A00%29%20Eastern%20Brazil&deviceTypeId=1&deviceUseTypeId=4&deviceVersion=0.1&enableAlerts=1&enableBattery=1&enableEmail=1&enableGeoFencing=1&enableImpact=1&enableSMS=1&enableSpeed=1&enableTemperature=1&enableTiers=1&enableTimeRange=1&heading_to=116.839996&jsonAddress=%7B%22place_id%22%3A%2224020287%22%2C%22licence%22%3A%22Data%20%C2%A9%20OpenStreetMap%20contributors%2C%20ODbL%201.0.%20http%3A%5C/%5C/www.openstreetmap.org%5C/copyright%22%2C%22osm_type%22%3A%22node%22%2C%22osm_id%22%3A%222355070909%22%2C%22lat%22%3A%22-23.5038297%22%2C%22lon%22%3A%22-46.6285165%22%2C%22display_name%22%3A%22Ita%C3%BA%20Personalit%C3%A9%2C%20Avenida%20Br%C3%A1s%20Leme%2C%20Jardim%20S%C3%A3o%20Bento%2C%20Casa%20Verde%2C%20SP%2C%20Microrregi%C3%A3o%20de%20S%C3%A3o%20Paulo%2C%20RMSP%2C%20Mesorregi%C3%A3o%20Metropolitana%20de%20S%C3%A3o%20Paulo%2C%20SP%2C%20Regi%C3%A3o%20Sudeste%2C%2002022-010%2C%20Brasil%22%2C%22address%22%3A%7B%22bank%22%3A%22Ita%C3%BA%20Personalit%C3%A9%22%2C%22road%22%3A%22Avenida%20Br%C3%A1s%20Leme%22%2C%22neighbourhood%22%3A%22Jardim%20S%C3%A3o%20Bento%22%2C%22suburb%22%3A%22Casa%20Verde%22%2C%22city_district%22%3A%22Casa%20Verde%22%2C%22city%22%3A%22SP%22%2C%22county%22%3A%22Microrregi%C3%A3o%20de%20S%C3%A3o%20Paulo%22%2C%22state_district%22%3A%22Mesorregi%C3%A3o%20Metropolitana%20de%20S%C3%A3o%20Paulo%22%2C%22state%22%3A%22SP%22%2C%22postcode%22%3A%2202022-010%22%2C%22country%22%3A%22Brasil%22%2C%22country_code%22%3A%22br%22%7D%2C%22boundingbox%22%3A%5B%22-23.5039297%22%2C%22-23.5037297%22%2C%22-46.6286165%22%2C%22-46.6284165%22%5D%7D&latitude=-23.504236000000000&longitude=-46.628792000000000&speed=9.000000&temperature=27.00&timeStamp=2016-10-07%2023%3A35%3A32&useTypeDescription=SENIOR&userDeviceAccessID=1&userID=1&valueBattery=25&valueEmails%5B%5D%5BpersonName%5D=Giulio%20Loffreda&valueEmails%5B%5D%5BpersonEmail%5D=giulio%40loffreda.com.br&valueEmails%5B%5D%5BemailId%5D=1&valueEmails%5B%5D%5BpersonName%5D=Daniel%20Lombardi&valueEmails%5B%5D%5BpersonEmail%5D=eu%40daniellombardi.com.br&valueEmails%5B%5D%5BemailId%5D=2&valueGeoFencing%5B%5D%5BgeoFencingTimeEnabled%5D=0&valueGeoFencing%5B%5D%5BgeoFencingAnalyseFriday%5D=1&valueGeoFencing%5B%5D%5BgeoFencingLongitude%5D=-46.639857300000020&valueGeoFencing%5B%5D%5BgeoFencingAddress%5D=Tv.%20Heliodora%2C%2014&valueGeoFencing%5B%5D%5BgeoFencingId%5D=5&valueGeoFencing%5B%5D%5BgeoFencingAnalyseMonday%5D=1&valueGeoFencing%5B%5D%5BgeoFencingAnalyseWednesday%5D=0&valueGeoFencing%5B%5D%5BgeoFencingAnalyseThursday%5D=1&valueGeoFencing%5B%5D%5BgeoFencingLatitude%5D=-23.503186700000000&valueGeoFencing%5B%5D%5BgeoFencingAnalyseTuesday%5D=1&valueGeoFencing%5B%5D%5BgeoFencingTypeId%5D=1&valueGeoFencing%5B%5D%5BgeoFencingTypeName%5D=ENTER&valueGeoFencing%5B%5D%5BgeoFencingTimeRange1%5D=0.150000000&valueGeoFencing%5B%5D%5BgeoFencingName%5D=Geo%201&valueGeoFencing%5B%5D%5BgeoFencingTimeRange2%5D=0.750000000&valueGeoFencing%5B%5D%5BgeoFencingAnalyseSunday%5D=0&valueGeoFencing%5B%5D%5BgeoFencingRadius%5D=744&valueGeoFencing%5B%5D%5BgeoFencingAnalyseSaturday%5D=1&valueSMS%5B%5D%5BpersonPhone%5D=%2B55%2011%20981378213&valueSMS%5B%5D%5BpersonName%5D=Daniel%20Lombardi&valueSMS%5B%5D%5BSMSId%5D=1&valueSpeed=62&valueTRange1=0.000000&valueTRange2=1.000000&valueTemperature=46&valueTiers%5B%5D%5BuserShareDeviceId%5D=6&valueTiers%5B%5D%5BacceptationDate%5D=%3Cnull%3E&valueTiers%5B%5D%5BsharedStatusId%5D=1&valueTiers%5B%5D%5BpersonPhone%5D=%2B55%2011%20981378213&valueTiers%5B%5D%5BpersonEmail%5D=eu%40daniellombardi.com.br&valueTiers%5B%5D%5BsharedStatus%5D=INVITE_SENT&valueTiers%5B%5D%5BsharedDate%5D=2016-08-17%2020%3A57%3A06&valueTiers%5B%5D%5BdestUserId%5D=60&valueTiers%5B%5D%5BpersonName%5D=Daniel%20Lombardi&valueTiers%5B%5D%5BuserShareDeviceId%5D=7&valueTiers%5B%5D%5BacceptationDate%5D=%3Cnull%3E&valueTiers%5B%5D%5BsharedStatusId%5D=1&valueTiers%5B%5D%5BpersonPhone%5D=&valueTiers%5B%5D%5BpersonEmail%5D=giulio%40loffreda.com.br&valueTiers%5B%5D%5BsharedStatus%5D=INVITE_SENT&valueTiers%5B%5D%5BsharedDate%5D=2016-10-04%2020%3A00%3A06&valueTiers%5B%5D%5BdestUserId%5D=1&valueTiers%5B%5D%5BpersonName%5D=Giulio" \
这应该可以工作,但是由于在这个对象中我有子数组,所以我的后端不理解为 json 对象。
愚蠢的技巧是它与 AFNetworking 一起工作。
我错过了什么吗?当然可以,但是什么?已阅读所有 Alamofire 和 SwiftyJSON 文档并尝试了多种类型的序列化。
编辑:
解决方案:
至少就我而言,我更改了一些参数,它的效果非常好:
alamoFireManager?.request("\(urlUserApi)\", method: .post, parameters: settings.dictionaryValue, encoding: URLEncoding.default, headers:["Authorization" : userData.apiKey, "Content-Type" : "application/x-www-form-urlencoded"])
.debugLog()
.responseJSON(completionHandler: { (response) in
switch response.result {
case .success:
let useType = JSON(response.result.value!)
if ((useType["error"].bool) == true) {
let error = NSError(domain: UserErrorDomain, code: -982, userInfo: [NSLocalizedDescriptionKey: translateStrings(useType["message"].string!)])
completion(nil, error)
} else {
completion(useType, nil)
}
case .failure(let error):
completion(nil, error)
}
})
这成功了:
"Content-Type" : "application/x-www-form-urlencoded"
以及将参数类型从 Parameter 更改为 JSON:
settings: JSON
并将其实现为字典:
settings.dictionaryValue
希望对大家有帮助
@zombie 的答案很好,只是没有用它来改变我的实现标准。
最佳答案
为了能够在 swift 中将 json 添加为字符串,我使用 http://bernhardhaeussner.de/odd/json-escape/ 对其进行了转换。
所以我的代码看起来像这样
let values = "{\n \"enableSMS\" : 1,\n \"deviceAssociationID\" : 12,\n \"timeStamp\" : \"2016-10-07 23:35:32\",\n \"userDeviceAccessID\" : 1,\n \"valueBattery\" : 25,\n \"deviceDescription\" : \"<null>\",\n \"deviceID\" : 1,\n \"valueTemperature\" : 46,\n \"valueTRange1\" : \"0.000000\",\n \"deviceTypeId\" : 1,\n \"latitude\" : \"-23.504236000000000\",\n \"enableEmail\" : 1,\n \"valueTiers\" : [\n {\n \"userShareDeviceId\" : 6,\n \"sharedStatusId\" : 1,\n \"sharedStatus\" : \"INVITE_SENT\",\n \"destUserId\" : 60,\n \"personEmail\" : \"eu@you.com\",\n \"sharedDate\" : \"2016-08-17 20:57:06\",\n \"personName\" : \"Daniel\",\n \"personPhone\" : \"+55 11 9999999999\",\n \"acceptationDate\" : null\n },\n {\n \"userShareDeviceId\" : 7,\n \"sharedStatusId\" : 1,\n \"sharedStatus\" : \"INVITE_SENT\",\n \"destUserId\" : 1,\n \"personEmail\" : \"x@y.com\",\n \"sharedDate\" : \"2016-10-04 20:00:06\",\n \"personName\" : \"John\",\n \"personPhone\" : \"\",\n \"acceptationDate\" : null\n }\n ],\n \"enableTimeRange\" : 1,\n \"deviceVersion\" : \"0.1\",\n \"valueSMS\" : [\n {\n \"SMSId\" : 1,\n \"personName\" : \"Daniel\",\n \"personPhone\" : \"+55 11 999999999\"\n }\n ],\n \"deviceName\" : \"Vovózinhaaaa\",\n \"jsonAddress\" : \"{\\\"place_id\\\":\\\"24020287\\\",\\\"licence\\\":\\\"Data © OpenStreetMap contributors, ODbL 1.0. http:\\\\\\/\\\\\\/www.openstreetmap.org\\\\\\/copyright\\\",\\\"osm_type\\\":\\\"node\\\",\\\"osm_id\\\":\\\"2355070909\\\",\\\"lat\\\":\\\"-23.5038297\\\",\\\"lon\\\":\\\"-46.6285165\\\",\\\"display_name\\\":\\\"Itaú Personalité, Avenida Brás Leme, Jardim São Bento, Casa Verde, SP, Microrregião de São Paulo, RMSP, Mesorregião Metropolitana de São Paulo, SP, Região Sudeste, 02022-010, Brasil\\\",\\\"address\\\":{\\\"bank\\\":\\\"Itaú Personalité\\\",\\\"road\\\":\\\"Avenida Brás Leme\\\",\\\"neighbourhood\\\":\\\"Jardim São Bento\\\",\\\"suburb\\\":\\\"Casa Verde\\\",\\\"city_district\\\":\\\"Casa Verde\\\",\\\"city\\\":\\\"SP\\\",\\\"county\\\":\\\"Microrregião de São Paulo\\\",\\\"state_district\\\":\\\"Mesorregião Metropolitana de São Paulo\\\",\\\"state\\\":\\\"SP\\\",\\\"postcode\\\":\\\"02022-010\\\",\\\"country\\\":\\\"Brasil\\\",\\\"country_code\\\":\\\"br\\\"},\\\"boundingbox\\\":[\\\"-23.5039297\\\",\\\"-23.5037297\\\",\\\"-46.6286165\\\",\\\"-46.6284165\\\"]}\",\n \"deviceJSONWeather\" : \"{\\\"coord\\\":{\\\"lon\\\":-46.63,\\\"lat\\\":-23.47},\\\"weather\\\":[{\\\"id\\\":802,\\\"main\\\":\\\"Clouds\\\",\\\"description\\\":\\\"scattered clouds\\\",\\\"icon\\\":\\\"03n\\\"}],\\\"base\\\":\\\"cmc stations\\\",\\\"main\\\":{\\\"temp\\\":299.26,\\\"pressure\\\":1023,\\\"humidity\\\":81,\\\"temp_min\\\":299.26,\\\"temp_max\\\":299.26},\\\"wind\\\":{\\\"speed\\\":3.08,\\\"deg\\\":70,\\\"gust\\\":3.08},\\\"rain\\\":{\\\"3h\\\":0.03},\\\"clouds\\\":{\\\"all\\\":36},\\\"dt\\\":1470863106,\\\"sys\\\":{\\\"type\\\":3,\\\"id\\\":135121,\\\"message\\\":0.0091,\\\"country\\\":\\\"BR\\\",\\\"sunrise\\\":1470821690,\\\"sunset\\\":1470862123},\\\"id\\\":3467431,\\\"name\\\":\\\"Cantareira\\\",\\\"cod\\\":200}\",\n \"acceleration\" : \"3.89743600\",\n \"temperature\" : \"27.00\",\n \"speed\" : \"9.000000\",\n \"valueEmails\" : [\n {\n \"emailId\" : 1,\n \"personName\" : \"John Doe\",\n \"personEmail\" : \"j@doe.com\"\n },\n {\n \"emailId\" : 2,\n \"personName\" : \"Daniel\",\n \"personEmail\" : \"eu@you.com\"\n }\n ],\n \"longitude\" : \"-46.628792000000000\",\n \"valueGeoFencing\" : [\n {\n \"geoFencingAnalyseSaturday\" : 1,\n \"geoFencingLongitude\" : \"-46.639857300000020\",\n \"geoFencingName\" : \"Geo 1\",\n \"geoFencingAddress\" : \"Tv. Heliodora, 14\",\n \"geoFencingLatitude\" : \"-23.503186700000000\",\n \"geoFencingTimeRange1\" : \"0.150000000\",\n \"geoFencingAnalyseSunday\" : 0,\n \"geoFencingTimeEnabled\" : 0,\n \"geoFencingAnalyseMonday\" : 1,\n \"geoFencingAnalyseTuesday\" : 1,\n \"geoFencingTypeId\" : 1,\n \"geoFencingTimeRange2\" : \"0.750000000\",\n \"geoFencingId\" : 5,\n \"geoFencingAnalyseFriday\" : 1,\n \"geoFencingRadius\" : 744,\n \"geoFencingAnalyseWednesday\" : 0,\n \"geoFencingTypeName\" : \"ENTER\",\n \"geoFencingAnalyseThursday\" : 1\n }\n ],\n \"enableImpact\" : 1,\n \"enableGeoFencing\" : 1,\n \"devicePicture\" : \"https:\\/\\/pic.com\\/devices\\/12.jpg\",\n \"userID\" : 1,\n \"enableAlerts\" : 1,\n \"useTypeDescription\" : \"SENIOR\",\n \"enableBattery\" : 1,\n \"valueSpeed\" : 62,\n \"batteryLevel\" : 73,\n \"valueTRange2\" : \"1.000000\",\n \"altitude\" : \"721.900024\",\n \"enableSpeed\" : 1,\n \"deviceTimeZoneName\" : \"(GMT -3:00) Eastern Brazil\",\n \"heading_to\" : \"116.839996\",\n \"enableTemperature\" : 1,\n \"enableTiers\" : 1,\n \"deviceStatus\" : \"ACTIVATED\",\n \"deviceSerialNumber\" : \"TRX00001\",\n \"alertsNonRead\" : 69,\n \"deviceUseTypeId\" : 4,\n \"deviceTimeZone\" : \"America\\/Sao_Paulo\"\n}"
var data = values.data(using: String.Encoding.utf8, allowLossyConversion: false)
do {
var json = try JSONSerialization.jsonObject(with: data!, options: [])
print(json)
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = json
Alamofire.request(request)
.responseJSON { response in
switch response.result {
case .failure(let error):
print(error)
if let data = response.data, let responseString = String(data: data, encoding: .utf8) {
print(responseString)
}
case .success(let responseObject):
print(responseObject)
}
}
}
catch {
print(error)
}
关于ios - 带有 Alamofire post 参数的 SwiftyJSON 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39983219/
我有:- var myArray:Array = array 我想要:- var myJSON:JSON = myArray as? JSON 但我收到警告:-从“数组”转换为无关类型“JSON”总是
真的很麻烦。我在 App Store 上有几个应用程序,其中一些使用 SwiftyJSON,但后一个很奇怪。我正在尝试将其上传到 App Store,但出现了这个奇怪的错误。 No suitable
从我之前的问题中你可以看出,我在解析 JSON 数据时遇到了很多麻烦。经过几天的头痛之后,我认为最好的方法仍然是使用 alamofire/swiftyjson。我还发现了 alamofire-swif
当我将我的 SwiftyJSON 文件添加到我的项目时,它有大约 45 个错误,其中大约 44 个将 as 更改为 as!。现在我被困在第 238 行的最后一个,然后我就可以走了。错误说: 无法将“A
我一直在使用模拟器来测试我的应用程序。今天我决定在模拟器中使用其他设备对其进行测试,令我惊讶的是它在某些设备上启动时崩溃,而在其他设备上却运行良好 我的应用构建运行于: iPad 空气 可调整大小的
这是问题的续集:dyld: Library not loaded: @rpath/SwiftyJSON.framework/SwiftyJSON 从头开始重建项目后(新项目、新 podfile、新文件
我试图弄清楚 SwiftyJSON 但我遇到了问题 下面显示的代码工作正常 import UIKit class ViewController: UIViewController {
我有对象 {"FIELD NAME":{ "SUBNAME":{ "FIELD_ONE":"DATA", "FIELD_TWO":"
我正在使用 SwiftyJSON,这很棒。但是,我在将 JSON(data:) 结果存储在我的 viewController 中时遇到问题。 SwiftyJSON 的标准使用效果很好。 let jso
我一直在学习 SWIFT 应用程序中的 JSON 解析。到目前为止,我一直在使用一个简单的免费 API,没有遇到任何问题,应用程序按设计运行。但现在我正在调用一个 API,该 API 返回一个数组内的
SwiftyJSON.swift 文件给我一个错误“NSNumber”对协议(protocol)“Comparable”的冗余一致性 extension NSNumber: Swift.Compara
我正在使用 Alamofire 从 API 获取数据。我正在使用 SwiftyJSON 来解析 JSON 响应。目前,我正在迭代产品数据,并希望提取产品详细信息并将其显示在 Collection Vi
我试图从我的测试目标包中读取一个文件,将该文件转换为 NSData,并将所述数据传递给我的类,然后类使用它来实例化 SwiftyJSON 实例。似乎我的数据生成正确,但是我的 SwiftyJSON 实
我尝试使用 SwiftyJSON 解析以下 JSON 结构,但我无法弄清楚如何循环遍历“sections”节点。我当前的代码返回每个部分的第一个部分节点,但我无法访问“Section 1b/Secti
我有一个由 .rawString() 转换的 JSON 对象的 NSArray,保存在 NSUserDefaults 上。 这是 lanesToReturn NSArray 的打印结果: ( "{\n
我有一个字典数组: var dictArray = [[String:String]]() 我附加了一些字典并将 dictArray 转换为 JSON: let json = JSON(dictArr
如何在不循环的情况下从一个数组到下一个数组? JSON:/image/34BtT.png 我尝试这样做 guard let items = self.json["data"]["reels_media
我有一个包含一些变量的类,我想通过使用 SwiftyJSON 解析 JSON 输出来创建此类的对象数组(我是 SwiftyJSON 的新手,因此在创建时遇到了一些问题一)并使用表格显示它们 谁能帮我创
我尝试用这种结构创建 JSON: var json: JSON = [ "params": [ "token": Utilities.token,
键“children”中包含的数组包含 100 项。 有没有办法告诉 SwiftyJSON 去抓取一个随机索引?我尝试创建一个随机数 var random = arc4random_uniform(2
我是一名优秀的程序员,十分优秀!