Notice
Recent Posts
Recent Comments
Link
스토리지
[3.25] C#으로 json파일 불러오기 복습 1 본문
using System;
namespace Study11
{
public class SongData
{
public int songId;
public string songName;
public string composer;
public int pastDifficulty;
public int presentDifficulty;
public float futureDifficulty;
public bool haveBeyond;
public float beyondDifficulty;
public override string ToString()
{
//문자열 보간 사용
return String.Format("{0 ,-2} {1, -35} {2, -35} {3, 13} {4, 3} {5, 5} {6, 5} {7, 5}",
this.songId, this.songName, this.composer, this.pastDifficulty, this.presentDifficulty, this.futureDifficulty, this.haveBeyond, this.beyondDifficulty);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Newtonsoft.Json;
namespace Study11
{
public class App
{
public App()
{
string path = File.ReadAllText("./song_data.json");
SongData[] songDatas = JsonConvert.DeserializeObject<SongData[]>(path);
Dictionary<int, SongData> dicSongDatas = songDatas.ToDictionary(x => x.songId);
foreach (var song in dicSongDatas)
{
Console.WriteLine(song.Value);
}
}
}
}
'Unity > 수업내용(C#)' 카테고리의 다른 글
[3.25] json 파일을 싱글턴 패턴으로 읽어오기 (0) | 2021.03.25 |
---|---|
[3.25] 싱글턴 패턴 (0) | 2021.03.25 |
[3.24] json 파일을 배열로 받아들이기 (0) | 2021.03.24 |
[3.24] Excel 파일을 json 형태로 바꾸기 (0) | 2021.03.24 |
[3.24] Event를 이용한 드론 조종 (0) | 2021.03.24 |
Comments