我从服务器获取值并将它们存储到Coredata.问题是当我从服务器获取数据并将它们存储在coredata中时,它表明我存储了我的值所有值.....
这些是我存储的数据:
[{
adName = Britannia;
adType = Video;
addescription = "Choco Muffills come with thick chocolate filling that will take you by surprise.";
clientImage = "http://api.weoneapp.com:8595/1464528609370.png";
clientName = Britannia;
endDate = "Just now";
entryId = 1478230186228;
likeFlag = 0;
mainImage = "";
newAdvertisement = 1;
noOfCount = 1367;
noOfLike = 2783;
seenAdvertisement = 0;
smilURL = "http://52.66.101.222:1935/vod/_definst_/1478230186228/smil:1478230186228.smil/playlist.m3u8";
sortDate = "2016-11-03T19:27:00.000Z";
startDate = "2016-11-03T19:27:00.000Z";
subTitle = "Britannia Cake Muffills";
thumbNail = "http://52.66.101.222:8595/video/1478230186228/1478230186228_thumbnail.png";
videoDownloadUrl = "http://52.66.101.222:8595/video/1478230186228/1478230186228_source.mp4";
}, {
adName = "Kwality …Run Code Online (Sandbox Code Playgroud) 我有这个对象 [Dictionary< String: Any>]
[{
"addCity" : "Xyz",
"addLandmark" : "Shopper",
"addCountry" : "Abc",
"addPincode" : "122001",
"isPrimary" : "false",
"addAddress" : "S44",
"addState" : "abc",
"addAddress2" : "Grand Road",
"addContact" : "11111111",
"addName" : "John"
}]
Run Code Online (Sandbox Code Playgroud)
并希望将其转换为:
"{\"addAddress\":\"S44\",\"addAddress2\":\"Grand Road\",\"addCity\":\"Xyz\",\"addContact\":\"11111111\",\"addCountry\":\"abc\",\"addLandmark\":\"Shopper\",\"addName\":\" John\",\"addPincode\":\"122002\",\"addState\":\"abc\",\"isPrimary\":true}"
Run Code Online (Sandbox Code Playgroud)
意味着我必须对上述值进行字符串化并尝试了各种方法但没有找到任何解决方案。
我试过这个
do {
let arrJson = try JSONSerialization.data(withJSONObject: dataAddress, options: JSONSerialization.WritingOptions.prettyPrinted)
let string = String(data: arrJson, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
let tempJson = string! as String
print("%%%%%%",tempJson)
}catch let error as NSError{
print(error.description)
}
Run Code Online (Sandbox Code Playgroud)
但它只是以 JSON 形式返回相同的内容。
请任何人都可以帮助我。