2005 年的错误 JObject 子项

error JObject children in 2005

我在 VB.NET 2005

中遇到关于 JObject 的问题
Dim result_post = SendRequest("http://" + IP + ":" + Port + "/scanlog/new", data, "POST")
TB_Memo.Text = result_post
Dim json As String = TB_Memo.Text
Dim ser As JObject = JObject.Parse(json)
Dim jdata As List(Of JToken) = ser.Children().ToList

并在

中收到消息错误
ser.Children().ToList" 

关于:

'ToList' is not a member of 'Newtonsoft.Json.Linq.JEnumerable(Of Newtonsoft.Json.Linq.JToken)'.

我尝试在第一个代码行添加这个,但仍然出错

Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq

我在 VB.NET 2010 年试过并成功了,但在 VB.NET 2005 年仍然出错,我使用 2005 编写真正的模块程序。 请帮助我,谢谢你的关心。

ToList 不是 JObject.Children(). Rather, it is the LINQ extension method Enumerable.ToList<TSource>(IEnumerable<TSource>) in the System.Linq 命名空间的方法或 属性。

不幸的是,Visual Studio 2005 does not support extension methods as they were added in VS 2008, and also does not support LINQ 因为它也是在 VS 2008 中添加的。

因此您需要使用传统的预 LINQ List(Of JToken) constructor:

Dim jdata As List(Of JToken) = new List(Of JToken)(ser.Children())

顺便说一句,如果您要使用 LINQ to JSON you may have difficulties porting to any version of Visual Studio earlier than 2008 since LINQ was introduced in that version.