2014-03-06 2 views
0

저는 웹 서버에서 얻은 일부 json을 비 직렬화하는 데 문제가 있습니다. 그리고 나는 그것이 formating의 beacuse라고 생각합니다. 이 같은json DeserializeObject in C# json.net을 사용하여

json으로보기 :

{ 
    "post_count": { 
     "total_posts": 1, 
     "sfw_total_posts": 1, 
     "use": 0 
    }, 
    "posts_per_page": 1, 
    "posts": [ 
     { 
      "guid": 10019127, 
      "wp_id": 656197, 
      "type": "media", 
      "title": "Test", 
      "path": "TestPath", 
      "publish_start": 1385559021, 
      "author": "Test", 
      "web_url": "http://www.test.com", 
      "nsfw": "No", 
      "modified": 1385532803, 
      "video": "No", 
      "likes": 484, 
      "dislikes": 51, 
      "main_category_id": 71, 
      "thumbnails": [ 
       { 
        "w": 120, 
        "h": 120 
       }, 
       { 
        "w": 240, 
        "h": 240 
       } 
      ], 
      "comments": 26 
     } 
    ], 
    "server": "100.200", 
    "time": 0.42163896560669 
} 

은 내가 사용하려는 나는 그것을 역 직렬화 할하지만 모든

LatestChive lastchives = JsonConvert.DeserializeObject<LatestChive>(jsonstring); 

후 사용하는 것이가에 대한 값으로 클래스를 만들었습니다 값은 null을 반환합니다 (단지 "게시물"에있는 항목 만 필요함).

"post_count"또는 "posts_per_page"로 시도하면 "posts"가 아닌 값을 얻을 수 있습니다

이 정보가 의미가 있고 쉽게 고치기를 바랍니다.

+2

참조 미래의 일을 위해

public class PostCount { public int total_posts { get; set; } public int sfw_total_posts { get; set; } public int use { get; set; } } public class Thumbnail { public int w { get; set; } public int h { get; set; } } public class Post { public int guid { get; set; } public int wp_id { get; set; } public string type { get; set; } public string title { get; set; } public string path { get; set; } public int publish_start { get; set; } public string author { get; set; } public string web_url { get; set; } public string nsfw { get; set; } public int modified { get; set; } public string video { get; set; } public int likes { get; set; } public int dislikes { get; set; } public int main_category_id { get; set; } public List<Thumbnail> thumbnails { get; set; } public int comments { get; set; } } public class LatestChive { public PostCount post_count { get; set; } public int posts_per_page { get; set; } public List<Post> posts { get; set; } public string server { get; set; } public double time { get; set; } } 

으로 클래스를 정의합니다. –

답변

3

당신이 당신의`LatestChive` 클래스를 보여 주었다 경우 도움이 될 http://json2csharp.com/

+1

정말 고마워요. –

관련 문제