JavaScriptに自信ニキ

1 : 2022/03/29(火) 21:57:16.81 ID:r9oAdKStMNIKU
JSONファイルを読み込んでhtmlに表示させたいんやが上手くいかない
読み込めてすらなさそうや
なんでなん?
ちなJSONファイルの中身はC#からシリアライズ化して書き込んでるから問題ないはず
2 : 2022/03/29(火) 21:58:23.51 ID:MfC4JZt20NIKU
tsconfigにresolveJsonModuleつけろ定期
3 : 2022/03/29(火) 21:58:28.28 ID:m28OfQwc0NIKU
ローカルのhtml?
6 : 2022/03/29(火) 21:59:06.72 ID:r9oAdKStMNIKU
>>3
せや
4 : 2022/03/29(火) 21:58:39.04 ID:r9oAdKStMNIKU
https://qiita.com/kunihiro9216/items/15339509604d66fdb961
ここを参考にしてJSONファイルを読み込むとこだけ変えてるんやが動かないんや
5 : 2022/03/29(火) 21:58:58.45 ID:KU95C4jN0NIKU
JSON.parseでオブジェクトで読み込めへんかったか
7 : 2022/03/29(火) 22:00:03.54 ID:1UN8BjEE0NIKU
まずはパソコンの電源を入れます
8 : 2022/03/29(火) 22:00:20.23 ID:r9oAdKStMNIKU
ちなこれで読み込んでる

$.getJSON(url, (data) => {
console.log(`id=${data.id}, name=${data.name}, email=${data.email}`);
});

14 : 2022/03/29(火) 22:02:42.41 ID:KU95C4jN0NIKU
>>8
ローカルにあるjsonならファイルシステム(fsで読み込まんの?
9 : 2022/03/29(火) 22:00:51.49 ID:r9oAdKStMNIKU
urlをhttps://ポート/test.jsonにしてるんやがダメやねんな
10 : 2022/03/29(火) 22:01:17.63 ID:r9oAdKStMNIKU
http://localhost:ポート/やった
11 : 2022/03/29(火) 22:01:44.45 ID:r9oAdKStMNIKU
助けてや
12 : 2022/03/29(火) 22:02:17.92 ID:m28OfQwc0NIKU
セキュリティの関係でローカルのhtmlでjson読む時はなんかしなきゃいけなかったような
13 : 2022/03/29(火) 22:02:24.41 ID:fQDjQn3z0NIKU
jsonファイルはBOM無しUTF-8か?
16 : 2022/03/29(火) 22:03:52.08 ID:r9oAdKStMNIKU
>>13
shiftJISや
21 : 2022/03/29(火) 22:05:22.67 ID:fQDjQn3z0NIKU
>>16
RFC 8259読んでみ
24 : 2022/03/29(火) 22:07:32.09 ID:LL+tXNzWMNIKU
>>21
utf8じゃないとダメなん?
htmlに表示させるのは日本語なんやが
28 : 2022/03/29(火) 22:08:50.41 ID:fQDjQn3z0NIKU
>>24
BOM無しUTF-8ってのがルールや
15 : 2022/03/29(火) 22:03:22.13 ID:KU95C4jN0NIKU
あ、普通のjsか
17 : 2022/03/29(火) 22:04:11.11 ID:MfC4JZt20NIKU
そんなめんどうなことせんでも同じ場所にあるなら普通にオブジェクトとしてimportできるやろ
30 : 2022/03/29(火) 22:09:28.16 ID:LL+tXNzWMNIKU
>>17の通り
htmlでimportすればええんか?
行数が可変だから動的にテーブルを作りたいんやが
18 : 2022/03/29(火) 22:04:12.04 ID:m28OfQwc0NIKU
apacheとかiisとか通せばそのままみいけるかも
19 : 2022/03/29(火) 22:04:23.93 ID:JAkAQ8fU0NIKU
console.logで一個一個出力してどこで詰まってるか確認するんや
20 : 2022/03/29(火) 22:05:02.02 ID:LL+tXNzWMNIKU
バックエンドでJSON生成してから読み込むんや
25 : 2022/03/29(火) 22:07:33.42 ID:MfC4JZt20NIKU
ちな同じ場所にあるならURLはtest.jsonだけでいいで
27 : 2022/03/29(火) 22:08:27.09 ID:LL+tXNzWMNIKU
>>25
多分それも試した
./test.jsonも試した
29 : 2022/03/29(火) 22:09:26.11 ID:KU95C4jN0NIKU
ローカルで読み込むとCORSに引っかかるから、無効にするか別の方法しないといけないやつや
31 : 2022/03/29(火) 22:09:53.55 ID:INgziWJS0NIKU
エラー貼れ定期
32 : 2022/03/29(火) 22:10:08.91 ID:3iioMeR4dNIKU
>>31
これ
33 : 2022/03/29(火) 22:10:30.35 ID:LL+tXNzWMNIKU
>>31
パソコン会社やし
34 : 2022/03/29(火) 22:10:31.24 ID:MfC4JZt20NIKU
普通にAJAXでbytebufferとして読み込んでutf8でtostringするしかないんちゃう?知らんけど
35 : 2022/03/29(火) 22:10:59.39 ID:LL+tXNzWMNIKU
Chromeのコンソール画面だとエラーなかったんだよなあらでも表示されなかった

コメント

  1. VegaZone より:

    I am based in Australia , and over the past while I made up my mind to check out [url=https://payinnv.tech]https://payinnv.tech[/url] purely out of curiosity. Right away, I noticed the casino itself: everything looks pretty clean, it is simple to get around, and what you’re looking for is quick to find. From my perspective, that’s a crucial point, because when the interface feels overwhelming or awkward, the desire to keep playing tends to disappear pretty quickly.

    I first found VegaZone when hunting for platforms with better layouts and crash-style games. Ultimately, I decided to test the format and see what it’s like normal gaming sessions were there. In that regard, my experience has been largely positive: everything feels straightforward, with no pointless clutter, and the platform comes across as calm overall.

    I also appreciated the fact that the platform has a decent selection of games, and there’s no a sense of being stuck to a single category. It’s easy to jump in for a brief visit, or spend more time if you’re in the mood. Personally I’ve always gravitated towards sites that you don’t need to take a long time figuring out the layout and can right away jump into exactly what you want to play.

    My favourite part at VegaZone was definitely the crash titles. Personally, I find them a lot better than regular slots, since they have a different pace and the sessions feel more engaging. There’s more engagement in the process, there are choices to make, and for that reason playing is more enjoyable to me than just spinning slots in the same rhythm.

    My own approach is to tend to approach things at a relaxed pace and more often than not choose smaller multipliers, rather than always hunting for massive x’s. It just sits more natural to me personally: things flow at a steadier pace, you can spend more time playing and enjoy the gameplay itself. If you’re not trying to turn every bet into a high-stakes moment, the experience feels far more enjoyable.

    Over the long run, such a style suits me enjoy best. With smaller targets, you can set your own rhythm, not burning through your balance and not making each session into an endless race after the jackpot. Personally, that makes the gaming experience better overall.

    To sum it up, VegaZone gave me quite a pleasant impression as a convenient site for easy-going gaming and regular sessions free from extra fuss. For those of you for whom crash titles, a clear interface and a more measured paced style of play appeal to you, VegaZone might work well perfectly.

タイトルとURLをコピーしました