質問編集履歴

2

参照元クラスの一部コード追加

2020/08/01 05:49

投稿

ko-ru
ko-ru

スコア27

test CHANGED
File without changes
test CHANGED
@@ -394,6 +394,70 @@
394
394
 
395
395
 
396
396
 
397
+ ```
398
+
399
+ 参照元クラス
400
+
401
+
402
+
403
+ let url = URL(string: ”ぐるなびAPI URL”)
404
+
405
+ let request = URLRequest(url: url!)
406
+
407
+ let session = URLSession.shared
408
+
409
+
410
+
411
+ session.dataTask(with: request){(data, response, error)in if error == nil,
412
+
413
+
414
+
415
+  let data = data,
416
+
417
+ ((response as? HTTPURLResponse) != nil) {
418
+
419
+
420
+
421
+ //デコード
422
+
423
+ let decoder: JSONDecoder = JSONDecoder()
424
+
425
+ decoder.dateDecodingStrategy = .iso8601
426
+
427
+ do {
428
+
429
+ //データ取得成功
430
+
431
+ let json:JsonReviewsList.Reviews = try decoder.decode(JsonReviewsList.Reviews.self, from: data)
432
+
433
+ let totalHitCount:Int = Int(json.total_hit_count)
434
+
435
+ let jsonreview = json.reviews
436
+
437
+  
438
+
439
+    for i in (0...totalHitCount-1) {
440
+
441
+ print(jsonreview[i].shopID)
442
+
443
+ print(jsonreview[i].shopName)
444
+
445
+ }
446
+
447
+ }catch {print ("error")}
448
+
449
+ }
450
+
451
+ }.resume()
452
+
453
+
454
+
455
+ ```
456
+
457
+
458
+
459
+
460
+
397
461
 
398
462
 
399
463
  ご教授よろしくお願いいたします。

1

JSONデータ

2020/08/01 05:49

投稿

ko-ru
ko-ru

スコア27

test CHANGED
File without changes
test CHANGED
@@ -378,6 +378,18 @@
378
378
 
379
379
  },
380
380
 
381
+ "1": {   ←※※※※※※※※※※※※※※※※※※※※※※※※※※※ 
382
+
383
+ "photo": {
384
+
385
+ "vote_id": "",
386
+
387
+ "photo_genre_id": "",
388
+
389
+
390
+
391
+ ----------- 省略 -----------
392
+
381
393
  ```
382
394
 
383
395