質問編集履歴
4
成形前のJSONに誤りがあったため修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -59,6 +59,10 @@
|
|
59
59
|
},
|
60
60
|
"kind": "structValue"
|
61
61
|
},
|
62
|
+
"webview": {
|
63
|
+
"boolValue": false,
|
64
|
+
"kind": "boolValue"
|
65
|
+
},
|
62
66
|
"event": {
|
63
67
|
"structValue": {
|
64
68
|
"fields": {
|
3
成形前のJSONに誤りがあったため修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,6 +16,21 @@
|
|
16
16
|
"replyPayload": {
|
17
17
|
"structValue": {
|
18
18
|
"fields": {
|
19
|
+
"title": {
|
20
|
+
"structValue": {
|
21
|
+
"fields": {
|
22
|
+
"format": {
|
23
|
+
"boolValue": false,
|
24
|
+
"kind": "boolValue"
|
25
|
+
},
|
26
|
+
"text": {
|
27
|
+
"stringValue": "選択",
|
28
|
+
"kind": "stringValue"
|
29
|
+
}
|
30
|
+
}
|
31
|
+
},
|
32
|
+
"kind": "structValue"
|
33
|
+
},
|
19
34
|
"comflow": {
|
20
35
|
"structValue": {
|
21
36
|
"fields": {
|
@@ -37,7 +52,7 @@
|
|
37
52
|
"kind": "boolValue"
|
38
53
|
},
|
39
54
|
"text": {
|
40
|
-
"stringValue": "
|
55
|
+
"stringValue": "トップに戻る",
|
41
56
|
"kind": "stringValue"
|
42
57
|
}
|
43
58
|
}
|
@@ -85,7 +100,7 @@
|
|
85
100
|
"kind": "boolValue"
|
86
101
|
},
|
87
102
|
"text": {
|
88
|
-
"stringValue": "
|
103
|
+
"stringValue": "前に戻る",
|
89
104
|
"kind": "stringValue"
|
90
105
|
}
|
91
106
|
}
|
@@ -103,21 +118,6 @@
|
|
103
118
|
}
|
104
119
|
},
|
105
120
|
"kind": "structValue"
|
106
|
-
},
|
107
|
-
"title": {
|
108
|
-
"structValue": {
|
109
|
-
"fields": {
|
110
|
-
"format": {
|
111
|
-
"boolValue": false,
|
112
|
-
"kind": "boolValue"
|
113
|
-
},
|
114
|
-
"text": {
|
115
|
-
"stringValue": "メニューまたは機種選択に戻る場合は、下のボタ ンを押してください。",
|
116
|
-
"kind": "stringValue"
|
117
|
-
}
|
118
|
-
}
|
119
|
-
},
|
120
|
-
"kind": "structValue"
|
121
121
|
}
|
122
122
|
}
|
123
123
|
},
|
2
試したコードと結果を追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -263,7 +263,7 @@
|
|
263
263
|
{
|
264
264
|
"replyPayload": {
|
265
265
|
"title": {
|
266
|
-
"text": "
|
266
|
+
"text": "選択"
|
267
267
|
}
|
268
268
|
}
|
269
269
|
},
|
@@ -275,7 +275,7 @@
|
|
275
275
|
"button": [
|
276
276
|
{
|
277
277
|
"label": {
|
278
|
-
"text": "
|
278
|
+
"text": "トップに戻る"
|
279
279
|
}
|
280
280
|
}
|
281
281
|
]
|
@@ -303,7 +303,7 @@
|
|
303
303
|
}
|
304
304
|
},
|
305
305
|
{
|
306
|
-
"text": "
|
306
|
+
"text": "前に戻る"
|
307
307
|
}
|
308
308
|
]
|
309
309
|
]
|
1
試したコードと結果を追記しました。実際には、else if (obj.boolValue)の処理も同様にありますが文字数の制限上省略させていただきました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -173,6 +173,143 @@
|
|
173
173
|
]
|
174
174
|
}
|
175
175
|
```
|
176
|
+
### 追記:試したコード・結果
|
177
|
+
試したコード↓
|
178
|
+
```javascript
|
179
|
+
let message = data.payload.fields.message;
|
180
|
+
const analysisArr = [];
|
181
|
+
analysis(message);
|
182
|
+
let payload = {message : analysisArr};
|
183
|
+
console.log(payload);
|
184
|
+
|
185
|
+
function analysis(obj) {
|
186
|
+
try {
|
187
|
+
console.log('obj => ' + JSON.stringify(obj));
|
188
|
+
let box = {};
|
189
|
+
if (obj.structValue) {
|
190
|
+
box = obj.structValue.fields;
|
191
|
+
Object.keys(box).forEach(function(key) {
|
192
|
+
analysisArr.push({[key] : {}});
|
193
|
+
console.log('analysisArr => ' + JSON.stringify(analysisArr));
|
194
|
+
analysis(box[key], key);
|
195
|
+
});
|
196
|
+
} else if (obj.listValue) {
|
197
|
+
analysisArr.push([]);
|
198
|
+
console.log('analysisArr => ' + JSON.stringify(analysisArr));
|
199
|
+
box = obj.listValue.values;
|
200
|
+
box.forEach(function(val, key) {
|
201
|
+
analysis(val);
|
202
|
+
});
|
203
|
+
} else if (obj.stringValue) {
|
204
|
+
const l = analysisArr.length;
|
205
|
+
const parent = analysisArr[l-1];
|
206
|
+
const parentKey = Object.keys(parent);
|
207
|
+
parent[parentKey[0]] = obj.stringValue;
|
208
|
+
console.log('analysisArr => ' + JSON.stringify(analysisArr));
|
209
|
+
for (let i = l-2; i > -1; i--) {
|
210
|
+
if (Object.prototype.toString.call(analysisArr[i]) === '[object Object]') { // 自分
|
211
|
+
const cpm = analysisArr[i];
|
212
|
+
console.log('\ncpm => ' + JSON.stringify(cpm));
|
213
|
+
const keyArr = Object.keys(cpm);
|
214
|
+
const child = analysisArr[i+1];
|
215
|
+
if (Object.prototype.toString.call(cpm[keyArr[0]]) === '[object Object]' && !Object.keys(cpm[keyArr[0]]).length) { // 自分のプロパティ
|
216
|
+
if (Object.prototype.toString.call(child) === '[object Array]') { // child
|
217
|
+
cpm[keyArr[0]] = child;
|
218
|
+
} else {
|
219
|
+
const childKey = Object.keys(child);
|
220
|
+
const type = Object.prototype.toString.call(child[childKey[0]]);
|
221
|
+
console.log('type => ' + type);
|
222
|
+
if (type === '[object Object]' || type === '[object String]' || type === '[object Number]' || type === '[object Boolean]') { // childのプロパティ
|
223
|
+
cpm[keyArr[0]] = {[childKey[0]] : child[childKey[0]]};
|
224
|
+
} else if (Object.prototype.toString.call(child[childKey[0]]) === '[object Array]') {
|
225
|
+
cpm[keyArr[0]] = child;
|
226
|
+
}
|
227
|
+
}
|
228
|
+
} else if (Object.prototype.toString.call(cpm[keyArr[0]]) === '[object Object]' && Object.keys(cpm[keyArr[0]]).length) {
|
229
|
+
if (Object.prototype.toString.call(child) === '[object Array]') { // child
|
230
|
+
cpm[keyArr[0]] = child;
|
231
|
+
//nestCount++;
|
232
|
+
} else {
|
233
|
+
const childKey = Object.keys(child);
|
234
|
+
cpm[childKey[0]] = child[childKey[0]];
|
235
|
+
//nestCount++;
|
236
|
+
}
|
237
|
+
} else if (Object.prototype.toString.call(cpm[keyArr[0]]) === '[object Array]') {
|
238
|
+
cpm[keyArr[0]].push(child);
|
239
|
+
}
|
240
|
+
analysisArr.pop();
|
241
|
+
console.log('analysisArr => ' + JSON.stringify(analysisArr));
|
242
|
+
} else if (Object.prototype.toString.call(analysisArr[i]) === '[object Array]') {
|
243
|
+
const child = analysisArr.pop();
|
244
|
+
analysisArr[i].push(child);
|
245
|
+
console.log('\nis Array');
|
246
|
+
console.log('analysisArr => ' + JSON.stringify(analysisArr));
|
247
|
+
}
|
248
|
+
}
|
249
|
+
}
|
250
|
+
return null;
|
251
|
+
|
252
|
+
} catch(error) {
|
253
|
+
console.log(error);
|
254
|
+
return null;
|
255
|
+
}
|
256
|
+
}
|
257
|
+
```
|
258
|
+
結果
|
259
|
+
```
|
260
|
+
{
|
261
|
+
"message": [
|
262
|
+
[
|
263
|
+
{
|
264
|
+
"replyPayload": {
|
265
|
+
"title": {
|
266
|
+
"text": "メニューまたは機種選択に戻る場合は、下のボタンを押してください。"
|
267
|
+
}
|
268
|
+
}
|
269
|
+
},
|
270
|
+
{
|
271
|
+
"format": false
|
272
|
+
},
|
273
|
+
{
|
274
|
+
"comflow": {
|
275
|
+
"button": [
|
276
|
+
{
|
277
|
+
"label": {
|
278
|
+
"text": "端末選択に戻る"
|
279
|
+
}
|
280
|
+
}
|
281
|
+
]
|
282
|
+
}
|
283
|
+
},
|
284
|
+
{
|
285
|
+
"format": false
|
286
|
+
},
|
287
|
+
{
|
288
|
+
"event": {
|
289
|
+
"name": "eventName1"
|
290
|
+
}
|
291
|
+
},
|
292
|
+
{
|
293
|
+
"event": {
|
294
|
+
"name": "eventName2"
|
295
|
+
}
|
296
|
+
},
|
297
|
+
{
|
298
|
+
"webview": false
|
299
|
+
},
|
300
|
+
{
|
301
|
+
"label": {
|
302
|
+
"format": false
|
303
|
+
}
|
304
|
+
},
|
305
|
+
{
|
306
|
+
"text": "メニューに戻る"
|
307
|
+
}
|
308
|
+
]
|
309
|
+
]
|
310
|
+
}
|
311
|
+
```
|
312
|
+
###
|
176
313
|
配列のときは **listValue:{values:[]}**,
|
177
314
|
オブジェクトのときは **structValue:{fields:{}}**,
|
178
315
|
文字列のときは **stringValue:"文字列"**,
|