我正在从我的 Web 服务获取数据到名为 PreGroup.cs 的文件中的 JSON 字符串中。
在该文件中,我有一个 Web 服务参考对象。
现在在 PreGroup.cs 文件中肯定还有一个方法,那就是:
public string LoadAllArticles()
{
try
{
//articles_list = null;
obj = new GBService.PreGroupbookSreviceSoapClient();
obj.LoadAllArticlesCompleted += (obj_LoadAllArticlesCompleted);
obj.LoadAllArticlesAsync();
obj.CloseAsync();
}
catch (Exception)
{
throw;
}
//This is string which will be passed to the caller of this method.
return articles_list;
}
这是负载:
void obj_LoadAllArticlesCompleted(object sender, GBService.LoadAllArticlesCompletedEventArgs e)
{
try
{
articles_list = e.Result.ToString();
}
catch (Exception Ex)
{
throw Ex;
}
MessageBox.Show("Welcome to Groupbook </br>" + AllArticleData);
obj.LoadAllArticlesCompleted -= (obj_LoadAllArticlesCompleted);
}
现在,当我在要加载所有文章的 Windows Phone 页面“Index.cs”中调用此方法时,我无法将该简单字符串转换回列表。
这是我的 Index.cs 类的代码,我尝试了很多方法来反序列化/解析/等,但我无法将该字符串转换为列表:
private void LoadArticles()
{
obj = new PreGroupbook();
string art= obj.LoadAllArticles();
// How to convert that string into List<GB_articles> ?????? I have several ways
MyArticles.ItemsSource = gb_li;
}
这是我要反序列化的字符串:
[{
"article_id": 1,
"article_title": "This is Test Article",
"created_timestamp": "\/Date(1346395093347)\/",
"modified_timestamp": null,
"article_category_id": 3,
"privacy_id": 1,
"subscribers_count": 51,
"votes_down_count": 21,
"article_tag": "My Best C++",
"votes_up_count": 42,
"isActive": true
}, {
"article_id": 2,
"article_title": "The flying Horse was seen",
"created_timestamp": "\/Date(1346395104223)\/",
"modified_timestamp": null,
"article_category_id": 3,
"privacy_id": 1,
"subscribers_count": 51,
"votes_down_count": 21,
"article_tag": "My Best C++",
"votes_up_count": 42,
"isActive": true
}, {
"article_id": 3,
"article_title": "iWatch is just amazing",
"created_timestamp": "\/Date(1346395105477)\/",
"modified_timestamp": null,
"article_category_id": 3,
"privacy_id": 1,
"subscribers_count": 51,
"votes_down_count": 21,
"article_tag": "My Best C++",
"votes_up_count": 42,
"isActive": true
}, {
"article_id": 4,
"article_title": "Oh My My....did you see that???",
"created_timestamp": "\/Date(1346395107890)\/",
"modified_timestamp": null,
"article_category_id": 3,
"privacy_id": 1,
"subscribers_count": 51,
"votes_down_count": 21,
"article_tag": "My Best C++",
"votes_up_count": 42,
"isActive": true
}]
我究竟做错了什么?