teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

5

2020/12/01 03:10

投稿

sfdust
sfdust

スコア1137

answer CHANGED
@@ -51,8 +51,9 @@
51
51
  ```
52
52
 
53
53
 
54
- あるべき tweetcontent.jsonの内容:**正しく読み込まれるはず**。:
54
+ あるべき tweetcontent.jsonのフォーマット:**正しく読み込まれるはず**。:
55
55
  (データ全体を{}で囲んでください)
56
+ (urlやファイル名は適当なので、質問者さんのものに合わせてください)
56
57
  ```
57
58
  {
58
59
  "contents":[

4

修正

2020/12/01 03:10

投稿

sfdust
sfdust

スコア1137

answer CHANGED
@@ -33,21 +33,20 @@
33
33
  最後の}をコメント扱いにするため先頭に#をつけてしまっているのではないでしょうか。
34
34
 
35
35
  ただしく読み込むためには、全体を{}で囲む必要があります。
36
+ (最後の「}」の前に#をつけているとエラーになるので削除してください)
36
37
 
37
38
  現状の tweetcontent.json(推測):**エラーになる**。:
38
39
  ```
39
40
  "contents":[
40
- {
41
+ {
41
- "img_url":"https://drive.google.com/file/d/xxxxxxxxxx/view?usp=sharing",
42
+ "img_url":"https://drive.google.com/file/d/xxxxxxxxxx/view?usp=sharing",
42
- "tweet_text":"test"
43
+ "tweet_text":"test"
44
+ },
45
+ {
46
+ "img_url":"https://drive.google.com/file/d/zzzzzzzzzzzzzz/view?usp=sharing",
47
+ "tweet_text":"test"
43
- }
48
+ }
44
- ],
45
- "contents":[
46
- {
47
- "img_url":"https://drive.google.com/file/d/zzzzzzzzzzzzzz/view?usp=sharing",
48
- "tweet_text":"test"
49
- }
50
- ]
49
+ ]
51
50
  #}
52
51
  ```
53
52
 
@@ -57,13 +56,11 @@
57
56
  ```
58
57
  {
59
58
  "contents":[
60
- {
61
- "img_url":"https://drive.google.com/file/d/xxxxxxxxxx/view?usp=sharing",
62
- "tweet_text":"test"
63
- }
64
- ],
65
- "contents":[
66
59
  {
60
+ "img_url":"https://drive.google.com/file/d/xxxxxxxxxx/view?usp=sharing",
61
+ "tweet_text":"test"
62
+ },
63
+ {
67
64
  "img_url":"https://drive.google.com/file/d/zzzzzzzzzzzz/view?usp=sharing",
68
65
  "tweet_text":"test"
69
66
  }

3

修正

2020/12/01 03:07

投稿

sfdust
sfdust

スコア1137

answer CHANGED
@@ -28,13 +28,13 @@
28
28
  -----------------------
29
29
  # 追記
30
30
  記載していただいたエラーメッセージから察するに、
31
- 元のcontents.jsonファイルの内容について
31
+ 元の:tweetcontent.jsonファイルの内容について
32
32
  先頭の{が欠けていると同時に、
33
33
  最後の}をコメント扱いにするため先頭に#をつけてしまっているのではないでしょうか。
34
34
 
35
35
  ただしく読み込むためには、全体を{}で囲む必要があります。
36
36
 
37
- 現状のcontents.json(推測):**エラーになる**。:
37
+ 現状の tweetcontent.json(推測):**エラーになる**。:
38
38
  ```
39
39
  "contents":[
40
40
  {
@@ -52,8 +52,8 @@
52
52
  ```
53
53
 
54
54
 
55
- あるべきcontents.json の内容:**正しく読み込まれるはず**。:
55
+ あるべき tweetcontent.jsonの内容:**正しく読み込まれるはず**。:
56
- データ全体を{}で囲んでください
56
+ データ全体を{}で囲んでください
57
57
  ```
58
58
  {
59
59
  "contents":[

2

追加

2020/12/01 03:04

投稿

sfdust
sfdust

スコア1137

answer CHANGED
@@ -22,4 +22,51 @@
22
22
  exit(0)
23
23
  #random.choice()でリストからランダムに要素を一つ取得
24
24
  return random.choice(json_data["contents"])
25
+ ```
26
+
27
+
28
+ -----------------------
29
+ # 追記
30
+ 記載していただいたエラーメッセージから察するに、
31
+ 元のcontents.jsonファイルの内容について
32
+ 先頭の{が欠けていると同時に、
33
+ 最後の}をコメント扱いにするため先頭に#をつけてしまっているのではないでしょうか。
34
+
35
+ ただしく読み込むためには、全体を{}で囲む必要があります。
36
+
37
+ 現状のcontents.json(推測):**エラーになる**。:
38
+ ```
39
+ "contents":[
40
+ {
41
+ "img_url":"https://drive.google.com/file/d/xxxxxxxxxx/view?usp=sharing",
42
+ "tweet_text":"test"
43
+ }
44
+ ],
45
+ "contents":[
46
+ {
47
+ "img_url":"https://drive.google.com/file/d/zzzzzzzzzzzzzz/view?usp=sharing",
48
+ "tweet_text":"test"
49
+ }
50
+ ]
51
+ #}
52
+ ```
53
+
54
+
55
+ あるべきcontents.json の内容:**正しく読み込まれるはず**。:
56
+ データ全体を{}で囲んでください。
57
+ ```
58
+ {
59
+ "contents":[
60
+ {
61
+ "img_url":"https://drive.google.com/file/d/xxxxxxxxxx/view?usp=sharing",
62
+ "tweet_text":"test"
63
+ }
64
+ ],
65
+ "contents":[
66
+ {
67
+ "img_url":"https://drive.google.com/file/d/zzzzzzzzzzzz/view?usp=sharing",
68
+ "tweet_text":"test"
69
+ }
70
+ ]
71
+ }
25
72
  ```

1

修正

2020/12/01 03:03

投稿

sfdust
sfdust

スコア1137

answer CHANGED
@@ -4,7 +4,7 @@
4
4
  どのような形でデータがjson.load関数に渡されているか探る必要があります。
5
5
 
6
6
  def get_tweet_content(json_file_path)関数の内容を下記のように変えた場合、どのようなエラーメッセージが出るでしょうか。
7
- (json.loadをtry~cathcで囲んでエラー内容を表示するようにしています。)
7
+ (json.loadをtry~catchで囲んでエラー内容を表示するようにしています。)
8
8
  出たエラーメッセージ全文を記載してください。
9
9
 
10
10
  ```python