如何在wp7中为android使用json服务



我已经为Iphone和android创建了json web服务,现在我想在我的windows phone 7应用程序中使用它。但我不知道如何使用它。

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Register(string emailID, string pwd, string name,bool sex)
{
    client_profile _client = new client_profile();
    _client.Email = emailID;
    _client.Password = pwd;
    _client.Gender = sex;
    _client.Firstname = name;
  retutn _client.Insert();

}

有很多博客文章描述了这一点,请尝试"WP7:如何在Windows Phone 7应用程序上使用JSON数据"。简而言之,使用WebClient获取数据,创建一个模型对象并用[DataContract][DataMember]对其进行注释,然后按如下方式反序列化:

//load into memory stream
using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(jsonString)))
{
    //parse into jsonser
    var ser = new DataContractJsonSerializer(typeof(MyPersonClass[]));
    MyPersonClass[] obj = (MyPersonClass[])ser.ReadObject(ms);
}

最新更新