https://ko.wikipedia.org/wiki/JSON
JSON - 위키백과, 우리 모두의 백과사전
위키백과, 우리 모두의 백과사전. JSON(제이슨[1], JavaScript Object Notation)은 속성-값 쌍(attribute–value pairs), 배열 자료형(array data types) 또는 기타 모든 시리얼화 가능한 값(serializable value) 또는 키-값
ko.wikipedia.org
https://shancarter.github.io/mr-data-converter/
Mr. Data Converter
shancarter.github.io
Online JSON Viewer and Formatter
jsonviewer.stack.hu
컴퓨터에 엑셀이 없다면 구글에서 엑셀기능을 활용할 것
사용법
엑셀로 데이터 테이블을 작성한다
그 뒤 아래의 사이트에서 컨버전한다
https://shancarter.github.io/mr-data-converter/
Mr. Data Converter
shancarter.github.io
Online JSON Viewer and Formatter
jsonviewer.stack.hu
그뒤 위 사이트에서 변환된 값을 넣고 [ Fomat ] 를 눌러서 메모장에 입력할 값을 만든다
그뒤 메모장의 확장자를 json으로 변경하여 json파일로 만들고
자신이 쓰려는 스크립트의 bin > Debug로 넣는다
Json 설치
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LearnCollection
{
public class App
{
//생성자
public App() {
Console.WriteLine("App클래스의 생성자 호출됨");
//1. JSON파일 읽기
string json = File.ReadAllText("./weapon_data.json");
Console.WriteLine(json);
//2. 역직렬화 (문자열 -> 객체)
//역직렬화 대상 클래스를 생성 (매핑클래스)
WeaponData[] weaponDatas =
JsonConvert.DeserializeObject<WeaponData[]>(json);
for (int i = 0; i < weaponDatas.Length; i++)
{
WeaponData weaponData = weaponDatas[i];
Console.WriteLine($"{weaponData.id}, {weaponData.name}");
}
}
}
}
출력 스크립트를 작성하고 자신이 bin의 Debug 폴더에 넣은 자료와 연동시킬 것
직렬화
객체 => 문자열
역직렬화
문자열 => 객체
Json파일을 읽어온다
Json문자열을 가져온다
Json문자열을 -> 오브젝트로 만든다
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LearnCollection
{
public class App
{
//생성자
public App() {
Console.WriteLine("App클래스의 생성자 호출됨");
//1. JSON파일 읽기
string json = File.ReadAllText("./weapon_data.json");
Console.WriteLine(json);
//2. 역직렬화 (문자열 -> 객체)
//역직렬화 대상 클래스를 생성 (매핑클래스)
WeaponData[] weaponDatas =
JsonConvert.DeserializeObject<WeaponData[]>(json);
//딕셔너리 컬렉션 인스턴스화
Dictionary<int, WeaponData> dic = new Dictionary<int, WeaponData>();
for (int i = 0; i < weaponDatas.Length; i++)
{
WeaponData weaponData = weaponDatas[i];
Console.WriteLine($"{weaponData.id}, {weaponData.name}");
dic.Add(weaponData.id, weaponData);
}
}
}
}
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LearnCollection
{
public class App
{
//생성자
public App() {
Console.WriteLine("App클래스의 생성자 호출됨");
//1. JSON파일 읽기
string json = File.ReadAllText("./weapon_data.json");
Console.WriteLine(json);
//2. 역직렬화 (문자열 -> 객체)
//역직렬화 대상 클래스를 생성 (매핑클래스)
WeaponData[] weaponDatas =
JsonConvert.DeserializeObject<WeaponData[]>(json);
//딕셔너리 컬렉션 인스턴스화
Dictionary<int, WeaponData> dic = new Dictionary<int, WeaponData>();
for (int i = 0; i < weaponDatas.Length; i++)
{
WeaponData weaponData = weaponDatas[i];
Console.WriteLine($"{weaponData.id}, {weaponData.name}");
dic.Add(weaponData.id, weaponData);
}
//딕셔너리 요소의 값 가져오기
WeaponData data = dic[100];
Console.WriteLine("{0} {1}", data.id, data.name);
//딕셔너리 요소를 순회
//반드시 foreach사용
foreach (KeyValuePair<int, WeaponData> pair in dic)
{
WeaponData elementData = pair.Value;
Console.WriteLine("{0}, {1}", pair.Key, elementData.name);
}
}
}
}
위의 강좌 스크립트를 참고하여 비주얼스튜디오에 적용할 것
강좌의 예는 WeaponData 변수가 들어갔음 이걸 자신이 쓰는 파일 명으로 다 바꿀 것
https://kr.piliapp.com/json/validator/
JSON 검사기
JSON 형식의 검증 및 검사 JSON 형식은 널리 웹 개발에 적용된다. JSON 문자열은 항상 네트워크 대역폭 및 문서 크기,하지만 읽기는 너무 열심히하고 디버깅을 저장 빈 공간, 들여 쓰기와 줄 바꿈을
kr.piliapp.com
JSON문법 검사기 사이트
'유니티 & Json' 카테고리의 다른 글
Json으로 세이브 파일 만들기, 로드 (0) | 2024.10.24 |
---|---|
유니티의 JsonUtility 지원 (1) | 2024.10.24 |
유니티와 JSON주의 할 점 (0) | 2024.10.24 |
유니티에서 JSON사용하기 (2) | 2024.10.22 |