開発環境
- Swift3.1
- macOs Sierra
使用しているWebアプリケーションフレームワークはKituraです。
JSONを作成するところはSwiftyJSONを使用しています。
コードは以下になります。
swift
1import Kitura 2import SwiftyJSON 3 4#if os(Linux) 5 import Glibs 6 srand(UInt32(time(nil))) 7#else 8 import Darwin.C 9#endif 10 11let router = Router() 12 13router.get("/") { 14 request, response, next in 15 response.send("Hello, World") 16 next() 17} 18 19router.get("/salutation") { 20 request, response, next in 21#if os(Linux) 22 let idx = Int(random() % salutations.count) 23#else 24 let idx = Int(arc4random_uniform(UInt32(salutations.count))) 25#endif 26 response.send(json: JSON(["name": "ほげ"])) 27 next() 28} 29 30Kitura.addHTTPServer(onPort: 8090, with: router) 31 32Kitura.run()
上のコードをswift build
して.build/debug/AppName
を実行して、
https://localhost:8090/salutation
にアクセスすると、以下が表示されます。
JSON
1{ 2 "name" : "縺輔d縺�" 3}
この文字化けの原因がわかりません。
詳しい方、どうそよろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー