質問編集履歴
4
成形前のJSONに誤りがあったため修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -120,6 +120,14 @@
|
|
120
120
|
|
121
121
|
},
|
122
122
|
|
123
|
+
"webview": {
|
124
|
+
|
125
|
+
"boolValue": false,
|
126
|
+
|
127
|
+
"kind": "boolValue"
|
128
|
+
|
129
|
+
},
|
130
|
+
|
123
131
|
"event": {
|
124
132
|
|
125
133
|
"structValue": {
|
3
成形前のJSONに誤りがあったため修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,6 +34,36 @@
|
|
34
34
|
|
35
35
|
"fields": {
|
36
36
|
|
37
|
+
"title": {
|
38
|
+
|
39
|
+
"structValue": {
|
40
|
+
|
41
|
+
"fields": {
|
42
|
+
|
43
|
+
"format": {
|
44
|
+
|
45
|
+
"boolValue": false,
|
46
|
+
|
47
|
+
"kind": "boolValue"
|
48
|
+
|
49
|
+
},
|
50
|
+
|
51
|
+
"text": {
|
52
|
+
|
53
|
+
"stringValue": "選択",
|
54
|
+
|
55
|
+
"kind": "stringValue"
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
},
|
62
|
+
|
63
|
+
"kind": "structValue"
|
64
|
+
|
65
|
+
},
|
66
|
+
|
37
67
|
"comflow": {
|
38
68
|
|
39
69
|
"structValue": {
|
@@ -76,7 +106,7 @@
|
|
76
106
|
|
77
107
|
"text": {
|
78
108
|
|
79
|
-
"stringValue": "
|
109
|
+
"stringValue": "トップに戻る",
|
80
110
|
|
81
111
|
"kind": "stringValue"
|
82
112
|
|
@@ -172,7 +202,7 @@
|
|
172
202
|
|
173
203
|
"text": {
|
174
204
|
|
175
|
-
"stringValue": "
|
205
|
+
"stringValue": "前に戻る",
|
176
206
|
|
177
207
|
"kind": "stringValue"
|
178
208
|
|
@@ -208,36 +238,6 @@
|
|
208
238
|
|
209
239
|
"kind": "structValue"
|
210
240
|
|
211
|
-
},
|
212
|
-
|
213
|
-
"title": {
|
214
|
-
|
215
|
-
"structValue": {
|
216
|
-
|
217
|
-
"fields": {
|
218
|
-
|
219
|
-
"format": {
|
220
|
-
|
221
|
-
"boolValue": false,
|
222
|
-
|
223
|
-
"kind": "boolValue"
|
224
|
-
|
225
|
-
},
|
226
|
-
|
227
|
-
"text": {
|
228
|
-
|
229
|
-
"stringValue": "メニューまたは機種選択に戻る場合は、下のボタ ンを押してください。",
|
230
|
-
|
231
|
-
"kind": "stringValue"
|
232
|
-
|
233
|
-
}
|
234
|
-
|
235
|
-
}
|
236
|
-
|
237
|
-
},
|
238
|
-
|
239
|
-
"kind": "structValue"
|
240
|
-
|
241
241
|
}
|
242
242
|
|
243
243
|
}
|
2
試したコードと結果を追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -528,7 +528,7 @@
|
|
528
528
|
|
529
529
|
"title": {
|
530
530
|
|
531
|
-
"text": "
|
531
|
+
"text": "選択"
|
532
532
|
|
533
533
|
}
|
534
534
|
|
@@ -552,7 +552,7 @@
|
|
552
552
|
|
553
553
|
"label": {
|
554
554
|
|
555
|
-
"text": "
|
555
|
+
"text": "トップに戻る"
|
556
556
|
|
557
557
|
}
|
558
558
|
|
@@ -608,7 +608,7 @@
|
|
608
608
|
|
609
609
|
{
|
610
610
|
|
611
|
-
"text": "
|
611
|
+
"text": "前に戻る"
|
612
612
|
|
613
613
|
}
|
614
614
|
|
1
試したコードと結果を追記しました。実際には、else if (obj.boolValue)の処理も同様にありますが文字数の制限上省略させていただきました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -348,6 +348,280 @@
|
|
348
348
|
|
349
349
|
```
|
350
350
|
|
351
|
+
### 追記:試したコード・結果
|
352
|
+
|
353
|
+
試したコード↓
|
354
|
+
|
355
|
+
```javascript
|
356
|
+
|
357
|
+
let message = data.payload.fields.message;
|
358
|
+
|
359
|
+
const analysisArr = [];
|
360
|
+
|
361
|
+
analysis(message);
|
362
|
+
|
363
|
+
let payload = {message : analysisArr};
|
364
|
+
|
365
|
+
console.log(payload);
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
function analysis(obj) {
|
370
|
+
|
371
|
+
try {
|
372
|
+
|
373
|
+
console.log('obj => ' + JSON.stringify(obj));
|
374
|
+
|
375
|
+
let box = {};
|
376
|
+
|
377
|
+
if (obj.structValue) {
|
378
|
+
|
379
|
+
box = obj.structValue.fields;
|
380
|
+
|
381
|
+
Object.keys(box).forEach(function(key) {
|
382
|
+
|
383
|
+
analysisArr.push({[key] : {}});
|
384
|
+
|
385
|
+
console.log('analysisArr => ' + JSON.stringify(analysisArr));
|
386
|
+
|
387
|
+
analysis(box[key], key);
|
388
|
+
|
389
|
+
});
|
390
|
+
|
391
|
+
} else if (obj.listValue) {
|
392
|
+
|
393
|
+
analysisArr.push([]);
|
394
|
+
|
395
|
+
console.log('analysisArr => ' + JSON.stringify(analysisArr));
|
396
|
+
|
397
|
+
box = obj.listValue.values;
|
398
|
+
|
399
|
+
box.forEach(function(val, key) {
|
400
|
+
|
401
|
+
analysis(val);
|
402
|
+
|
403
|
+
});
|
404
|
+
|
405
|
+
} else if (obj.stringValue) {
|
406
|
+
|
407
|
+
const l = analysisArr.length;
|
408
|
+
|
409
|
+
const parent = analysisArr[l-1];
|
410
|
+
|
411
|
+
const parentKey = Object.keys(parent);
|
412
|
+
|
413
|
+
parent[parentKey[0]] = obj.stringValue;
|
414
|
+
|
415
|
+
console.log('analysisArr => ' + JSON.stringify(analysisArr));
|
416
|
+
|
417
|
+
for (let i = l-2; i > -1; i--) {
|
418
|
+
|
419
|
+
if (Object.prototype.toString.call(analysisArr[i]) === '[object Object]') { // 自分
|
420
|
+
|
421
|
+
const cpm = analysisArr[i];
|
422
|
+
|
423
|
+
console.log('\ncpm => ' + JSON.stringify(cpm));
|
424
|
+
|
425
|
+
const keyArr = Object.keys(cpm);
|
426
|
+
|
427
|
+
const child = analysisArr[i+1];
|
428
|
+
|
429
|
+
if (Object.prototype.toString.call(cpm[keyArr[0]]) === '[object Object]' && !Object.keys(cpm[keyArr[0]]).length) { // 自分のプロパティ
|
430
|
+
|
431
|
+
if (Object.prototype.toString.call(child) === '[object Array]') { // child
|
432
|
+
|
433
|
+
cpm[keyArr[0]] = child;
|
434
|
+
|
435
|
+
} else {
|
436
|
+
|
437
|
+
const childKey = Object.keys(child);
|
438
|
+
|
439
|
+
const type = Object.prototype.toString.call(child[childKey[0]]);
|
440
|
+
|
441
|
+
console.log('type => ' + type);
|
442
|
+
|
443
|
+
if (type === '[object Object]' || type === '[object String]' || type === '[object Number]' || type === '[object Boolean]') { // childのプロパティ
|
444
|
+
|
445
|
+
cpm[keyArr[0]] = {[childKey[0]] : child[childKey[0]]};
|
446
|
+
|
447
|
+
} else if (Object.prototype.toString.call(child[childKey[0]]) === '[object Array]') {
|
448
|
+
|
449
|
+
cpm[keyArr[0]] = child;
|
450
|
+
|
451
|
+
}
|
452
|
+
|
453
|
+
}
|
454
|
+
|
455
|
+
} else if (Object.prototype.toString.call(cpm[keyArr[0]]) === '[object Object]' && Object.keys(cpm[keyArr[0]]).length) {
|
456
|
+
|
457
|
+
if (Object.prototype.toString.call(child) === '[object Array]') { // child
|
458
|
+
|
459
|
+
cpm[keyArr[0]] = child;
|
460
|
+
|
461
|
+
//nestCount++;
|
462
|
+
|
463
|
+
} else {
|
464
|
+
|
465
|
+
const childKey = Object.keys(child);
|
466
|
+
|
467
|
+
cpm[childKey[0]] = child[childKey[0]];
|
468
|
+
|
469
|
+
//nestCount++;
|
470
|
+
|
471
|
+
}
|
472
|
+
|
473
|
+
} else if (Object.prototype.toString.call(cpm[keyArr[0]]) === '[object Array]') {
|
474
|
+
|
475
|
+
cpm[keyArr[0]].push(child);
|
476
|
+
|
477
|
+
}
|
478
|
+
|
479
|
+
analysisArr.pop();
|
480
|
+
|
481
|
+
console.log('analysisArr => ' + JSON.stringify(analysisArr));
|
482
|
+
|
483
|
+
} else if (Object.prototype.toString.call(analysisArr[i]) === '[object Array]') {
|
484
|
+
|
485
|
+
const child = analysisArr.pop();
|
486
|
+
|
487
|
+
analysisArr[i].push(child);
|
488
|
+
|
489
|
+
console.log('\nis Array');
|
490
|
+
|
491
|
+
console.log('analysisArr => ' + JSON.stringify(analysisArr));
|
492
|
+
|
493
|
+
}
|
494
|
+
|
495
|
+
}
|
496
|
+
|
497
|
+
}
|
498
|
+
|
499
|
+
return null;
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
} catch(error) {
|
504
|
+
|
505
|
+
console.log(error);
|
506
|
+
|
507
|
+
return null;
|
508
|
+
|
509
|
+
}
|
510
|
+
|
511
|
+
}
|
512
|
+
|
513
|
+
```
|
514
|
+
|
515
|
+
結果
|
516
|
+
|
517
|
+
```
|
518
|
+
|
519
|
+
{
|
520
|
+
|
521
|
+
"message": [
|
522
|
+
|
523
|
+
[
|
524
|
+
|
525
|
+
{
|
526
|
+
|
527
|
+
"replyPayload": {
|
528
|
+
|
529
|
+
"title": {
|
530
|
+
|
531
|
+
"text": "メニューまたは機種選択に戻る場合は、下のボタンを押してください。"
|
532
|
+
|
533
|
+
}
|
534
|
+
|
535
|
+
}
|
536
|
+
|
537
|
+
},
|
538
|
+
|
539
|
+
{
|
540
|
+
|
541
|
+
"format": false
|
542
|
+
|
543
|
+
},
|
544
|
+
|
545
|
+
{
|
546
|
+
|
547
|
+
"comflow": {
|
548
|
+
|
549
|
+
"button": [
|
550
|
+
|
551
|
+
{
|
552
|
+
|
553
|
+
"label": {
|
554
|
+
|
555
|
+
"text": "端末選択に戻る"
|
556
|
+
|
557
|
+
}
|
558
|
+
|
559
|
+
}
|
560
|
+
|
561
|
+
]
|
562
|
+
|
563
|
+
}
|
564
|
+
|
565
|
+
},
|
566
|
+
|
567
|
+
{
|
568
|
+
|
569
|
+
"format": false
|
570
|
+
|
571
|
+
},
|
572
|
+
|
573
|
+
{
|
574
|
+
|
575
|
+
"event": {
|
576
|
+
|
577
|
+
"name": "eventName1"
|
578
|
+
|
579
|
+
}
|
580
|
+
|
581
|
+
},
|
582
|
+
|
583
|
+
{
|
584
|
+
|
585
|
+
"event": {
|
586
|
+
|
587
|
+
"name": "eventName2"
|
588
|
+
|
589
|
+
}
|
590
|
+
|
591
|
+
},
|
592
|
+
|
593
|
+
{
|
594
|
+
|
595
|
+
"webview": false
|
596
|
+
|
597
|
+
},
|
598
|
+
|
599
|
+
{
|
600
|
+
|
601
|
+
"label": {
|
602
|
+
|
603
|
+
"format": false
|
604
|
+
|
605
|
+
}
|
606
|
+
|
607
|
+
},
|
608
|
+
|
609
|
+
{
|
610
|
+
|
611
|
+
"text": "メニューに戻る"
|
612
|
+
|
613
|
+
}
|
614
|
+
|
615
|
+
]
|
616
|
+
|
617
|
+
]
|
618
|
+
|
619
|
+
}
|
620
|
+
|
621
|
+
```
|
622
|
+
|
623
|
+
###
|
624
|
+
|
351
625
|
配列のときは **listValue:{values:[]}**,
|
352
626
|
|
353
627
|
オブジェクトのときは **structValue:{fields:{}}**,
|