SliverLight 解析 Json 的有关问题
SliverLight 解析 Json 的问题
你好,我在 SliverLight 项目中需要去解析一个 ASP.NET WebApi服务提供的json数据。
直接浏览 WebApi 服务 Uri 显示数据如下:
----------------------------------------------------------------
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<ArrayOfProduct xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/HelloWebApi.Models">
<Product>
<Category>Groceries</Category>
<Id>1</Id>
<Name>Arthur Jan</Name>
<Price>1.39</Price>
</Product>
</ArrayOfProduct>
----------------------------------------------------------------
SliverLight 解析 JSON 相关程序代码如下:
----------------------------------------------------------------
var buffer = System.Text.Encoding.UTF8.GetBytes(e.Result);
var ms = new MemoryStream(buffer);
var jsonObject = System.Json.JsonObject.Load(ms) as System.Json.JsonObject;
textBox1.Text = e.Result + "\r\n";
textBox1.Text += string.Format("代号:{0},名称:{1},分类:{2},价格:{3}",
jsonObject["Id"].ToString(),
jsonObject["Category"].ToString(),
jsonObject["Name"].ToString(),
jsonObject["Price"].ToString()
);
----------------------------------------------------------------
e.Result 显示的数据如下:
[{"Id":1,"Name":"Arthur Jan","Category":"Groceries","Price":1.39}]
但是 VS2010 却会在 以下程序区段出现错误:
-----------------------------------
textBox1.Text += string.Format("代号:{0},名称:{1},分类:{2},价格:{3}",
jsonObject["Id"].ToString(),
jsonObject["Category"].ToString(),
jsonObject["Name"].ToString(),
jsonObject["Price"].ToString()
你好,我在 SliverLight 项目中需要去解析一个 ASP.NET WebApi服务提供的json数据。
直接浏览 WebApi 服务 Uri 显示数据如下:
----------------------------------------------------------------
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<ArrayOfProduct xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/HelloWebApi.Models">
<Product>
<Category>Groceries</Category>
<Id>1</Id>
<Name>Arthur Jan</Name>
<Price>1.39</Price>
</Product>
</ArrayOfProduct>
----------------------------------------------------------------
SliverLight 解析 JSON 相关程序代码如下:
----------------------------------------------------------------
var buffer = System.Text.Encoding.UTF8.GetBytes(e.Result);
var ms = new MemoryStream(buffer);
var jsonObject = System.Json.JsonObject.Load(ms) as System.Json.JsonObject;
textBox1.Text = e.Result + "\r\n";
textBox1.Text += string.Format("代号:{0},名称:{1},分类:{2},价格:{3}",
jsonObject["Id"].ToString(),
jsonObject["Category"].ToString(),
jsonObject["Name"].ToString(),
jsonObject["Price"].ToString()
);
----------------------------------------------------------------
e.Result 显示的数据如下:
[{"Id":1,"Name":"Arthur Jan","Category":"Groceries","Price":1.39}]
但是 VS2010 却会在 以下程序区段出现错误:
-----------------------------------
textBox1.Text += string.Format("代号:{0},名称:{1},分类:{2},价格:{3}",
jsonObject["Id"].ToString(),
jsonObject["Category"].ToString(),
jsonObject["Name"].ToString(),
jsonObject["Price"].ToString()