在windows phone 7上解析json时出错

在windows phone 7上解析json时出错,json,windows-phone-7,Json,Windows Phone 7,我从一开始就学习了教程 但是当我想用我自己的json实现它时,我得到了一条错误消息 无法将当前JSON对象(例如{“名称”:“值”})反序列化为类型“System.Collections.Generic.List`1[BelajarJson.RootObject]”,因为该类型需要JSON数组(例如[1,2,3])才能正确反序列化。 若要修复此错误,请将JSON更改为JSON数组(例如[1,2,3]),或更改反序列化类型,使其成为可以从JSON对象反序列化的正常.NET类型(例如,不是integ

我从一开始就学习了教程

但是当我想用我自己的json实现它时,我得到了一条错误消息

无法将当前JSON对象(例如{“名称”:“值”})反序列化为类型“System.Collections.Generic.List`1[BelajarJson.RootObject]”,因为该类型需要JSON数组(例如[1,2,3])才能正确反序列化。 若要修复此错误,请将JSON更改为JSON数组(例如[1,2,3]),或更改反序列化类型,使其成为可以从JSON对象反序列化的正常.NET类型(例如,不是integer之类的基元类型,也不是数组或列表之类的集合类型)。还可以将JsonObjectAttribute添加到类型中,以强制它从JSON对象反序列化。 路径“错误代码”,第2行,位置13

Content.cs

namespace BelajarJson
{
    public class Content
    {
    public int id { get; set; }
    public string type { get; set; }
    public string label { get; set; }
    public string icon { get; set; }
    public string url { get; set; }
    public int timestamp { get; set; }
    public string key { get; set; }
    }
}
Paging.cs

namespace BelajarJson
{
public class Paging
{
    public int current_page { get; set; }
    public int total_page { get; set; }
    public int total_all { get; set; }
    public int limit_per_page { get; set; }
}
}
RootObject.cs

using System.Collections.Generic;

namespace BelajarJson
{
public class RootObject
{
    public int err_code { get; set; }
    public string message { get; set; }
    public Paging paging { get; set; }
    public List<Content> contents { get; set; }
}
}
使用System.Collections.Generic;
名称空间JSON
{
公共类根对象
{
公共整数错误代码{get;set;}
公共字符串消息{get;set;}
公共分页{get;set;}
公共列表内容{get;set;}
}
}
MainPage.xaml.xs

using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Reactive;
using Newtonsoft.Json;

namespace BelajarJson
{
public partial class MainPage : PhoneApplicationPage
{
    // Constructor
    public MainPage()
    {
        InitializeComponent();
    }

    private void Load_Click(object sender, RoutedEventArgs e)
    {




        var w = new WebClient();
        Observable
          .FromEvent<DownloadStringCompletedEventArgs>(w, "DownloadStringCompleted")
          .Subscribe(r =>
          {
              var deserialized =
                JsonConvert.DeserializeObject<List<RootObject>>(r.EventArgs.Result);
              PhoneList.ItemsSource = deserialized;
          });
        w.DownloadStringAsync(
          new Uri("http://yumugee.com/json.txt"));
    }
}
}
使用系统;
使用System.Collections.Generic;
Net系统;
使用System.Windows;
使用Microsoft.Phone.Controls;
使用Microsoft.Phone.Reactive;
使用Newtonsoft.Json;
名称空间JSON
{
公共部分类主页:PhoneApplicationPage
{
//建造师
公共主页()
{
初始化组件();
}
私有无效加载\单击(对象发送者,路由目标e)
{
var w=新的WebClient();
可观察
.FromEvent(w,“下载字符串已完成”)
.订阅(r=>
{
变量反序列化=
反序列化对象(r.EventArgs.Result);
PhoneList.ItemsSource=反序列化;
});
w、 下载StringAsync(
新Uri(“http://yumugee.com/json.txt"));
}
}
}
我试着在谷歌上搜索同样的问题,但还是没有成功。
你对如何解决这个问题有什么建议吗?谢谢

您是否确认结果实际上是一个对象数组,而不仅仅是一个对象。List()的构造函数可以采用IEnumerable,如数组,但不能采用单个对象

JSON数组应该看起来像[{“name”:“value”},{“name”:“value”}]