- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的测试 vb.net MVC Web 应用程序中,我有这个 json....
Public Class Person
Public Property Name As String
Public Property Age As Byte
Public Sub New(name As String, age As Byte)
Me.Name = name
Me.Age = age
End Sub
End Class
Function GetPerson() As JsonResult
Dim p As New Person("John Doe", 50)
Return Json(p, JsonRequestBehavior.AllowGet)
End Function
在 Monotouch 中我得到了这个...
JsonObject j;
Uri address = new Uri("http://mysite/home/GetPerson");
HttpWebRequest httpReq = (HttpWebRequest)HttpWebRequest.Create (address);
using (HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse ()) {
Stream s = httpRes.GetResponseStream ();
j = (JsonObject)JsonObject.Load (s);
}
还有这个类...
Public Class Person {
Public string Name { get; set; }
Public byte Age { get; set; }
}
如何将 JsonObject j 解析为 Person 类? ..我希望像 Person p = (Person)j.value;
谢谢!魔力
最佳答案
首先,我会使用 int 来表示 Age。但假设 JSON 结构如下:
{
"Name" : "John Doe",
"Age" : 100,
}
如果你想使用 System.Json 中烘焙的东西:
var person = new Person()
var obj = JsonObject.Parse(json);
person.Name = obj["Name"].ToString();
person.Age = (int)obj["Age"];
我强烈建议使用 ServiceStack.Text不过,它是一个高度优化的极其快速的库,用于使用 JSON,并且与 MonoTouch 和 Mono for Android 兼容......开箱即用!
您可以查看使用 ServiceStack 使用 JSON 的 API here .
关于json - 单点触控 : Deserialize JSON from MVC to Montouch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8450720/
是否可以在 iOS6 中控制快门速度? 我正在使用 C# Monotouch/Xamarin 构建我的应用程序。 谢谢。 最佳答案 没有。根据this question , Apple 不提供任何公共
在我的测试 vb.net MVC Web 应用程序中,我有这个 json.... Public Class Person Public Property Name As String
几周来我一直在开发单点触控 opengl iphone 游戏。就在昨天,它还在我的测试硬件(iPhone 4)上正常构建和运行。但是当我昨天加载项目时,它给了我编译错误: Framework 'Mon
我最近更新到 http://monotouch.net/Releases/MonoTouch_4/MonoTouch_4.0.0 之后,当尝试构建我的解决方案时,monodevelop 给了我一个错误
我是一名优秀的程序员,十分优秀!