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

时间:2012-03-23 05:57:45

标签: json web-services windows-phone-7

我已经为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();

}

1 个答案:

答案 0 :(得分:0)

有很多博客文章描述了这一点,请尝试"WP7: How to consume JSON data on a Windows Phone 7 application"。简而言之,使用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);
}