Reputation: 803
This is my Json
{
"count":2,
"threads":[
{
"thread_id":346568,
"node_id":75,
"title":"Gi\u1ea3i ph\u00e1p th\u1ed5i bay m\u00f9i h\u00f4i n\u00e1ch t\u1ef1 tin h\u01a1n trong ng\u00e0y h\u00e8",
"reply_count":0,
"view_count":2,
"user_id":339597,
"username":"giangdaigia20",
"post_date":1434435728,
"sticky":0,
"discussion_state":"visible",
"discussion_open":1,
"discussion_type":"",
"first_post_id":2468576,
"first_post_likes":0,
"last_post_date":1434435728,
"last_post_id":2468576,
"last_post_user_id":339597,
"last_post_username":"giangdaigia20",
"prefix_id":2,
"block_adsense":0,
"thumbnail_url":"",
"thumbnail_cache_waindigo":"a:8:{s:13:\"thumbnail_url\";s:69:\"http:\/\/trihoinach.org\/wp-content\/uploads\/2015\/04\/Tri-hoi-nach5555.jpg\";s:12:\"thumbnailUrl\";s:69:\"http:\/\/trihoinach.org\/wp-content\/uploads\/2015\/04\/Tri-hoi-nach5555.jpg\";s:5:\"width\";s:2:\"48\";s:6:\"height\";s:2:\"48\";s:9:\"max-width\";s:2:\"48\";s:10:\"max-height\";s:2:\"48\";s:17:\"vertical-position\";i:0;s:19:\"horizontal-position\";i:0;}",
"custom_fields":[
],
"socia l_forum_id":0,
"live_waindigo":0,
"current_event_id_waindigo":0,
"google_event_id_waindigo":"",
"social_forum_title":null,
"social_forum_user_id":null,
"social_forum_style_id":null,
"absolute_url":"http:\/\/dev.handheld.vn\/threads\/346568\/"
},
{
"thread_id":346567,
"node_id":85,
"title":"Nh\u1edd c\u00e1c b\u00e1c t\u01b0 v\u1ea5n d\u00f9m em 2 c\u00e1i \u0111\u1ed3ng h\u1ed3 Citizen n\u00e0y",
"reply_count":1,
"view_count":4,
"user_id":156695,
"username":"gamap",
"post_date":1434430984,
"sticky":0,
"discussion_state":"visible",
"discussion_open":1,
"discussion_type":"",
"first_post_id":2468575,
"first_post_likes":0,
"last_post_date":1434443484,
"last_post_id":2468577,
"last_post_user_id":156695,
"last_post_username":"gamap",
"prefix_id":95,
"block_adsense":0,
"thumbnail_url":"",
"thumbnail_cache_waindigo":"a:8:{s:13:\"thumbnail_url\";s:86:\"http:\/\/i16.photobucket.com\/albums\/b3\/vozmember\/shopdongho\/citizen\/real\/BU0011-55Aa.jpg\";s:12:\"thumbnailUrl\";s:86:\"http:\/\/i16.photobucket.com\/albums\/b3\/vozmember\/shopdongho\/ci tizen\/real\/BU0011-55Aa.jpg\";s:5:\"width\";s:2:\"48\";s:6:\"height\";s:2:\"48\";s:9:\"max-width\";s:2:\"48\";s:10:\"max-height\";s:2:\"48\";s:17:\"vertical-position\";i:0;s:19:\"horizontal-position\";i:0;}",
"custom_fields":[
],
"social_forum_id":0,
"live_waindigo":0,
"current_event_id_waindigo":0,
"google_event_id_waindigo":"",
"social_forum_title":null,
"social_forum_user_id":null,
"social_forum_style_id":null,
"absolute_url":"http:\/\/dev.handheld.vn\/threads\/34656 7\/"
}
]
}
This is my class define
class Thread_Result
{
public string count { get; set; }
[JsonProperty("threads")]
public Threads threads { get; set; }
}
class Threads
{
[JsonProperty("thread_id")]
public string thread_id { get; set; }
[JsonProperty("node_id")]
public string node_id { get; set; }
[JsonProperty("title")]
public string title { get; set; }
[JsonProperty("reply_count")]
public string reply_count { get; set; }
[JsonProperty("view_count")]
public string view_count { get; set; }
[JsonProperty("user_id")]
public string user_id { get; set; }
[JsonProperty("post_date")]
public string post_date { get; set; }
[JsonProperty("sticky")]
public string sticky { get; set; }
[JsonProperty("discussion_state")]
public string discussion_state { get; set; }
[JsonProperty("discussion_open")]
public string discussion_open { get; set; }
[JsonProperty("discussion_type")]
public string discussion_type { get; set; }
[JsonProperty("first_post_id")]
public string first_post_id { get; set; }
[JsonProperty("first_post_likes")]
public string first_post_likes { get; set; }
[JsonProperty("last_post_date")]
public string last_post_date { get; set; }
[JsonProperty("last_post_id")]
public string last_post_id { get; set; }
[JsonProperty("last_post_user_id")]
public string last_post_user_id { get; set; }
[JsonProperty("last_post_username")]
public string last_post_username { get; set; }
[JsonProperty("prefix_id")]
public string prefix_id { get; set; }
[JsonProperty("block_adsense")]
public string block_adsense { get; set; }
[JsonProperty("thumbnail_url")]
public string thumbnail_url { get; set; }
[JsonProperty("thumbnail_cache_waindigo")]
public string thumbnail_cache_waindigo { get; set; }
[JsonProperty("custom_fields")]
public string custom_fields { get; set; }
[JsonProperty("social_forum_id")]
public string social_forum_id { get; set; }
[JsonProperty("live_waindigo")]
public string live_waindigo { get; set; }
[JsonProperty("current_event_id_waindigo")]
public string current_event_id_waindigo { get; set; }
[JsonProperty("google_event_id_waindigo")]
public string google_event_id_waindigo { get; set; }
[JsonProperty("social_forum_title")]
public string social_forum_title { get; set; }
[JsonProperty("social_forum_user_id")]
public string social_forum_user_id { get; set; }
[JsonProperty("social_forum_style_id")]
public string social_forum_style_id { get; set; }
[JsonProperty("absolute_url")]
public string absolute_url { get; set; }
}
But i got error
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[AppHandHeld.Class.Threads]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'count', line 1, position 9.
Upvotes: 1
Views: 149
Reputation: 29668
This is a problem for a start:
[JsonProperty("threads")]
public Threads threads { get; set; }
Which to the parser looks like:
{
"threads": { <single thread object> }
}
It needs to be:
[JsonProperty("threads")]
public Threads[] threads { get; set; }
Which looks like:
{
"threads": [<array of thread objects>]
}
Which is how it is in the JSON sample you provided. Then you also have:
[JsonProperty("custom_fields")]
public string custom_fields { get; set; }
Which would mean in the JSON:
{
"custom_fields": "<some string>"
}
However in the JSON it is in fact:
{
"custom_fields": [<an array>]
}
Which should be something like:
[JsonProperty("custom_fields")]
public string[] custom_fields { get; set; }
And again you have in Thread_Result
:
[JsonProperty("count")]
public string Count { get; set; }
This should be:
[JsonProperty("count")]
public int Count { get; set; }
In fact you've done that for pretty much all of your numeric values, try and use the correct value types and let the JSON parser do the parsing for you.
Start fixing these basic issues and see how you get on.
Upvotes: 4