JSON 사용하기2

2013. 2. 20. 10:06Programming/C#

이전 포스팅에서 설명한 방법대로 C#에서 JSON을 사용해도 무방하지만

해당 경우는 반드시 MemoryStream을 이용해야 하는 경우이다.

String으로 받은 JSON 문자열을 일일이 parsing 해 주지 않고 객체로 변경할 수 없을까? 하는 고민에 빠져있던 중

괜찮은 JSON Library 발견!!

JSON for .NET

사용 방법은 아래와 같다.

using System.Net.Json;
class Program
{
static void Main(string[] args)
{
String inJson = "{'name':'test', 'type':'test'}";
JsonTextParser parser = new JsonTextParser();
JsonObject obj = parser.Parse(outJson);
JsonObjectCollection col = (JsonObjectCollection)obj;
string name = (string)col["name"].GetValue();
string type = (string)col["type"].GetValue();
}
}
view raw gistfile1.cs hosted with ❤ by GitHub