나는 XML 파일에서 제어 정보를 저장과 같이하는 데 사용 :JSON에 컨트롤을 직렬화하는 방법은 무엇입니까?
<Controls>
<Label Id="heading" Text="This is a heading!" FontStyle="(FontStyleDataHere)" Location="20, 10" />
<Label Id="bodyText" Text="This is Body text." FontStyle="(FontStyleDataHere)" Location="20, 70" />
</Controls>
나는 작년 한 코드의 많은 페이지의 인쇄 된 버전을 찾고있다, 그것은 내가 가진 유일한 백업이었다 왼쪽으로 지금 그것을 찾을 수 없습니다.
그리고 내가 어떻게 이런 일을했는지 기억할 수 없기 때문에 나는 XML이 엄청나게 지루하다는 것을 항상 알아 차린다. 그래서 JSON을 사용하지 않을까요? 지금
은, 위의 코드를 부여, 나는 Person 형의 클래스를 생성하고 객체를 직렬화하고 파일에 기록 할 수 있었다 ... 좀 더 쉽게 보인다 (또는 콘솔 - 무엇이든) :using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
namespace SerializeToJson
{
class Program
{
[DataContract]
internal class Person
{
[DataMember]
internal String Name;
[DataMember]
internal Int32 Age;
}
static void Main(string[] args)
{
Person person = new Person()
{
Name = "Jason rules.",
Age = 19
};
MemoryStream stream = new MemoryStream();
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Person));
serializer.WriteObject(stream, person);
stream.Position = 0;
StreamReader reader = new StreamReader(stream);
Console.Write("Json form of Person object: ");
Console.WriteLine(reader.ReadToEnd());
Console.ReadKey();
}
}
}
하지만 문제는 컨트롤을 Json으로 직렬화하는 방법을 모르겠습니다. 그리고 이것이 내가 정말로 필요로하는 것입니다. 그리고 분명히 나중의 시점에서 필요로 할 것이고, deserialize하기 때문에 런타임에 다시 생성 할 수 있습니다.
JSON을 사용하여이 작업을 수행 할 수 있습니까? 아니면 XML을 계속 사용 하시겠습니까?
무엇 당신이를 위해 필요합니까? – tucaz
나는 사용자가 원하는대로 전체 사용자 인터페이스를 재배치 할 수있는 응용 프로그램을 가지고 있으므로 제어 정보와 상태를 파일로 저장하고 다시 검색 할 수 있어야합니다. – James