質問編集履歴

2

Json文字列を追加しました。

2019/02/05 08:46

投稿

navesanta
navesanta

スコア198

test CHANGED
File without changes
test CHANGED
@@ -158,7 +158,13 @@
158
158
 
159
159
  ```
160
160
 
161
+ 格納したいJson文字列データ
161
162
 
163
+ ```ここに言語を入力
164
+
165
+ [{"faceId":"12345-678","faceRectangle":{"top":10,"left":20,"width":30,"height":30},"faceAttributes":{"age":55.0}}]
166
+
167
+ ```
162
168
 
163
169
  ネットで半日ほど調べたのですが同じような事例は(英語で)いくつかあるのですが
164
170
 

1

コードおよびエラーメッセージを修正しました。

2019/02/05 08:46

投稿

navesanta
navesanta

スコア198

test CHANGED
File without changes
test CHANGED
@@ -56,7 +56,7 @@
56
56
 
57
57
  Debug.Log("contentString:" + contentString);
58
58
 
59
- Debug.Log(GetComponent<PlayerInfo>().CreateFromJSON(contentString));
59
+ Debug.Log(PlayerInfo.CreateFromJSON(contentString));
60
60
 
61
61
  }
62
62
 
@@ -86,11 +86,11 @@
86
86
 
87
87
 
88
88
 
89
- public PlayerInfo CreateFromJSON(string jsonString){
89
+ public static PlayerInfo CreateFromJSON(string jsonString){
90
90
 
91
91
  return JsonUtility.FromJson<PlayerInfo>(jsonString);
92
92
 
93
- Debug.Log("playerInfo2.faceId:" + faceId);
93
+ Debug.Log("playerInfo2.faceId:" + faceId);
94
94
 
95
95
  Debug.Log("playerInfo2.faceRactangle.top:" + playerInfo2.faceRactangle.top);
96
96
 
@@ -134,11 +134,27 @@
134
134
 
135
135
  ```ここに言語を入力
136
136
 
137
- Assets/Scripts/FaceDetectionWebCamTexture.cs(219,23): error CS0120:
137
+ ArgumentException: JSON must represent an object type.
138
138
 
139
- An object reference is required for the non-static field, method,
139
+ UnityEngine.JsonUtility.FromJson (System.String json, System.Type type) (at /Users/builduser/buildslave/unity/build/Modules/JSONSerialize/Public/JsonUtility.bindings.cs:50)
140
140
 
141
+ UnityEngine.JsonUtility.FromJson[T] (System.String json) (at /Users/builduser/buildslave/unity/build/Modules/JSONSerialize/Public/JsonUtility.bindings.cs:33)
142
+
143
+ PlayerInfo.CreateFromJSON (System.String jsonString) (at Assets/Scripts/PlayerInfo.cs:11)
144
+
145
+ OpenCVForUnityExample.FaceDetectionWebCamTexture+<MakeAnalysisRequest>d__22.MoveNext () (at Assets/Scripts/FaceDetectionWebCamTexture.cs:220)
146
+
141
- or property 'Component.GetComponent<PlayerInfo>()'
147
+ --- End of stack trace from previous location where exception was thrown ---
148
+
149
+ System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <>:0)
150
+
151
+ System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) (at <>:0)
152
+
153
+ UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnitySynchronizationContext.cs:111)
154
+
155
+ UnityEngine.UnitySynchronizationContext.Exec () (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnitySynchronizationContext.cs:72)
156
+
157
+ UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnitySynchronizationContext.cs:93)
142
158
 
143
159
  ```
144
160