11 ŞUBAT 2010, PERŞEMBE
Özel C JSON Nesne Dönüştürme# nesne?
Benim C doldurmak için kolay bir yoldur# JSON nesnesi, AJAX ile geçirilen bir Nesne?
//Bu JSON Nesne C için sayfa JSON kullanarak# WEBMETHOD geçirilir.stringify
{
"user" : {
"name" : "asdf",
"teamname" : "b",
"email" : "c",
"players" : ["1",
"2"]
}
}
//C JSON Nesnesi alır# WebMetod
[WebMethod]
public static void SaveTeam(Object user)
{
}
//C# JSON Nesne yapısını temsil eden bir Sınıf WebMethod geçti
public class User
{
public string name { get; set; }
public string teamname { get; set; }
public string email { get; set; }
public Array players { get; set; }
}
CEVAP
11 ŞUBAT 2010, PERŞEMBE
C JSON kullanmak için iyi bir yolu# JSON.NET ile
JSON.NET - Official site Quick Starts & API Documentation ile çalışmanıza yardımcı olur.
Bunu kullanmak için nasıl bir örnek:
public class User
{
public User(string json)
{
JObject jObject = JObject.Parse(json);
JToken jUser = jObject["user"];
name = (string) jUser["name"];
teamname = (string) jUser["teamname"];
email = (string) jUser["email"];
players = jUser["players"].ToArray();
}
public string name { get; set; }
public string teamname { get; set; }
public string email { get; set; }
public Array players { get; set; }
}
// Use
private void Run()
{
string json = @"{""user"":{""name"":""asdf"",""teamname"":""b"",""email"":""c"",""players"":[""1"",""2""]}}";
User user = new User(json);
Console.WriteLine("Name : " user.name);
Console.WriteLine("Teamname : " user.teamname);
Console.WriteLine("Email : " user.email);
Console.WriteLine("Players:");
foreach (var player in user.players)
Console.WriteLine(player);
}
Bunu Paylaş:
Bir JSON yanıt NodeJS (nesne/dizi dize...
C dön " JSON dize içine nesne .NET 4...
C Özel nesne seri hale getirmek için n...
Nesne dize JSON dönüştürmek...
Bir tarihi bir DateTime dize dönüştürm...