AWS LambdaとAPI Gatewayを使って日本語をJSON形式で返そうとしています。
Lambda関数実行時は日本語は正しく出力されているのですが、unityのコンソール上で日本語の部分が文字化けしてしまいます。
※数字など日本語以外は正しく表示されています。
コードは以下の通りです。
AWSではPython3.6を使い、unity上ではC#のスクリプトを使用しています。
AWS Lambda関数のコード
import json import re print('Loading function') def user_word(): return "こんにちは" def lambda_handler(event, context): tim="20180622_1912_58" m = re.match('(\d{4})(\d{2})(\d{2})_(\d{2})(\d{2})_(\d{2})$',tim) if m: print (m.group(1, 2, 3, 4, 5, 6)) else: print [-1] * 6 year=m.group(1) month=m.group(2) day=m.group(3) hour=m.group(4) minute=m.group(5) second=m.group(6) print (year,month,day,hour,minute,second) text = user_word() print (hour) hour2= hour if text=="おはよう" and hour2>4 and hour2 <11: print(event['word1']) return event['word1'],'#挨拶',hour2 elif text=="こんにちは": #print(event['word2']) data = { "word1": event['word2'], "tag":"#認識", "hour":hour } return data else text=="こんばんは": print(event['word3']) return event['word3'],'#挨拶',hour
unity上でアタッチされているスクリプトのコード
using
1using System.Collections.Generic; 2using UnityEngine; 3using System; 4[Serializable] 5public class Info 6{ 7 8 public string word1; 9 public string word2; 10 public string word3; 11 12} 13 14 15 16public class test1 : MonoBehaviour { 17 18 string test1_url = "APIのURL"; 19 20 string API_Key = "APIKey"; 21 22 void Start() 23 { 24 StartCoroutine(getApiLog()); 25 } 26 27 28 IEnumerator getApiLog() 29 { 30 Dictionary<string, string> headers = new Dictionary<string, string>(); 31 headers.Add("Content-Type", "application/json;charset=UTF-8"); 32 33 headers.Add("x-api-key", "APIKey"); 34 35 36 var data = new Info(); 37 data.word1= "おはよう"; 38 data.word2 = "こんにちは"; 39 data.word3 = "こんばんは"; 40 41 var json = JsonUtility.ToJson(data); 42 Debug.Log(json); 43 byte[] bytedata = System.Text.Encoding.UTF8.GetBytes(json); 44 45 test1_url = test1_url; 46 47 WWW www = new WWW(test1_url, bytedata, headers); 48 yield return www; 49 Debug.Log(www.text); 50 } 51} 52 53
補足 API Gatewayのレスポンス設定は以下の通りに設定してあります。
回答1件
あなたの回答
tips
プレビュー