JSON.NET의 JsonConvert 클래스를 사용하여 개체로 일부 JSON을 deserialize하려고합니다.JSON.NET으로 이상한 구조의 JSON을 역 직렬화
코드 나는 JSON 구조 샘플을 사용하고 있습니다 :
var desObj = JsonConvert.DeserializeObject<Market>("{\"success\":\"1\",\"return\":
{\"sellorders\":
[{\"sellprice\":\"0.00001099\",\"quantity\":\"60.00000000\",\"total\":\"0.00065940\"},
{\"sellprice\":\"0.00001100\",\"quantity\":\"1000.00000000\",\"total\":\"0.01100000\"},
{\"sellprice\":\"0.00001105\",\"quantity\":\"60.00000000\",\"total\":\"0.01200\"}]}}");
그리고 내 시장 클래스 :
class Market
{
[JsonProperty("success")]
public int Success { get; set; }
[JsonProperty("sellorders")]
public List<SellOrder> SellOrders {get; set;}
[JsonProperty("buyorders")]
public List<BuyOrder> BuyOrders {get; set;}
}
public class SellOrder
{
[JsonProperty("sellprice")]
public decimal SellPrice { get; set; }
[JsonProperty("quantity")]
public decimal Quantity { get; set; }
[JsonProperty("total")]
public decimal Total { get; set; }
}
public class BuyOrder
{
[JsonProperty("buyprice")]
public decimal BuyPrice { get; set; }
[JsonProperty("quantity")]
public decimal Quantity { get; set; }
[JsonProperty("total")]
public decimal Total { get; set; }
}
나에게 문제를 일으키는 것은 데이터가 아래에 있다는 사실이다 ' return '키를 누르십시오. 리턴 키를 제거하면 완벽하게 작동합니다. 그런 식으로 매각/매입 주문을 검색 한 후, 반환 동적 속성 목록 만들기 실험
foreach(SellOrder sellorder in desObj.SellOrders)
{
Console.WriteLine(sellorder.total.ToString());
}
나는 시도했다, 그러나 아무것도에 보인다 : 어떻게 이런 식으로 행동하는 내 시장 객체를 받고 가겠어요 작업. 어떤 아이디어?
나의 현재 주위에 작업은 다음과 같이 원래 JSON을 수정하는 것입니다 : 결과 = result.Replace ("반환 \"을 {\ "" , ""); 결과 = result.Substring (0, result.Length - 1); ... 작동하지만, 확실히 해킹입니다. 하나 있다면 청소기 솔루션을 선호 할 것입니다! – Anonymous