您的位置:首页 > Web前端 > JavaScript

使用Json.NET出现“文档的顶层无效。处理资源 URl 时出错。第 1 行,位置: 1

2010-05-13 22:27 603 查看


很惭愧昨天才知道json net这个东东。。。

下载地址:http://james.newtonking.com/projects/json-net.aspx

Serialization Example

Product product = new Product();
product.Name = "Apple";
product.Expiry = new DateTime(2008, 12, 28);
product.Price = 3.99M;
product.Sizes = new string[] { "Small", "Medium", "Large" };
string json = JsonConvert.SerializeObject(product);
//{
// "Name": "Apple",
//  "Expiry": new Date(1230422400000),
//  "Price": 3.99,
// "Sizes": [
//    "Small",
//    "Medium",
//    "Large"
//  ]
//}
Product deserializedProduct = JsonConvert.DeserializeObject<Product>(json);



在输出是添加:

Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Response.ContentType = "text/plain";

问题解决
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐