Skip to content

Commit

Permalink
json打印中文
Browse files Browse the repository at this point in the history
  • Loading branch information
MQZHot committed May 31, 2018
1 parent 907a3b2 commit 7628340
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
5 changes: 5 additions & 0 deletions DaisyNet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.BackgroundModes = {
enabled = 0;
};
};
};
};
};
Expand Down
Binary file not shown.
1 change: 0 additions & 1 deletion DaisyNet/DaisyNet/DaisyValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ public struct DaisyValue<Value> {
self.response = response
}
}

11 changes: 8 additions & 3 deletions DaisyNet/DaisyNet/RequestManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,12 @@ public class DaisyResponse {
DaisyLog(response.request?.url?.absoluteString ?? "")
}
switch response.result {
case .success(let value):
case .success(_):
if openResultLog {
DaisyLog(value)
if let data = response.data,
let str = String(data: data, encoding: .utf8) {
DaisyLog(str)
}
}
if self.cache {/// 写入缓存
CacheManager.default.setObject(response.data, forKey: self.cacheKey)
Expand Down Expand Up @@ -236,7 +239,9 @@ public class DaisyJsonResponse: DaisyResponse {
DispatchQueue.main.async {/// 主线程
if openResultLog {
DaisyLog("=================缓存=====================")
DaisyLog(json)
if let str = String(data: data, encoding: .utf8) {
DaisyLog(str)
}
}
completion(json)
}
Expand Down
17 changes: 11 additions & 6 deletions DaisyNet/GetViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,26 @@ class GetViewController: UIViewController {
@IBOutlet weak var textView: UITextView!
@IBOutlet weak var cacheTextView: UITextView!

let url = "http://api.travels.app887.com/api/Articles.action"
let params = ["keyword" : "", "npc" : "0", "opc" : "20", "type" : "热门视频", "uid" : "2321"]
// let url = "http://api.travels.app887.com/api/Articles.action"
// let params = ["keyword" : "", "npc" : "0", "opc" : "20", "type" : "热门视频", "uid" : "2321"]

let url = "http://app.chatm.com/chatm-app/getADS?type=0"
let params : [String: Any] = [:]

override func viewDidLoad() {
super.viewDidLoad()

DaisyNet.openResultLog = false
// DaisyNet.openResultLog = true

DaisyNet.timeoutIntervalForRequest(4)
DaisyNet.request(url, params: params).cache(true).responseCacheAndString { value in
DaisyNet.request(url, params: params).cache(true).responseCacheAndJson { value in
switch value.result {
case .success(let string):

if value.isCacheData {
self.cacheTextView.text = string
// self.cacheTextView.text = string
} else {
self.textView.text = string
// self.textView.text = string
}

case .failure(let error):
Expand Down
14 changes: 7 additions & 7 deletions DaisyNet/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPhotoLibraryUsageDescription</key>
<string>是否允许打开相册</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
Expand All @@ -27,6 +20,13 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSPhotoLibraryUsageDescription</key>
<string>是否允许打开相册</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand Down

0 comments on commit 7628340

Please sign in to comment.