Search code examples
jsonvb.netlinqvisual-studio-2005

error JObject children in 2005


I have problem about JObject in VB.NET 2005

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

and got message error in

ser.Children().ToList" 

about:

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

I try add this at first code row,but still error

Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq

I tried in VB.NET 2010 and worked,but still error in VB.NET 2005 and im using 2005 for real module program. please help me and thanks for your concern.


Solution

  • ToList is not a method or property of JObject.Children(). Rather, it is the LINQ extension method Enumerable.ToList<TSource>(IEnumerable<TSource>) in the System.Linq namespace.

    Unfortunately, Visual Studio 2005 does not support extension methods as they were added in VS 2008, and also does not support LINQ as that was also added in VS 2008.

    Thus you will need to use the traditional pre-LINQ List(Of JToken) constructor:

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

    As an aside, if you are going to use LINQ to JSON you may have difficulties porting to any version of Visual Studio earlier than 2008 since LINQ was introduced in that version.