Home > Back-end >  Which namespace should I use to access Json operations? (Xamarin.Forms 2021 Year)
Which namespace should I use to access Json operations? (Xamarin.Forms 2021 Year)

Time:12-28

I tried using "using Newtonsoft.Json.Linq;" – GET ERROR – Using directive is unnecessary

dynamic stuff = JObject.Parse("{ 'Name': 'Jon Smith', 'Address': { 'City': 'New York', 'State': 'NY' }, 'Age': 42 }");

string name = stuff.Name;
string address = stuff.Address.City;

I also tried to use "using Json.NET" – GET ERROR – Using directive is unnecessary

dynamic stuff = JsonConvert.DeserializeObject("{ 'Name': 'Jon Smith', 'Address': { 'City': 'New York', 'State': 'NY' }, 'Age': 42 }");

string name = stuff.Name;
string address = stuff.Address.City;

it only works for me – "using Org.Json" – but I didn't understand how to use the library

Why do I get the error "Using directive is unnecessary"?

i use VS2019(8.10.16.2) Net.Standard.Library(2.0.3)

CodePudding user response:

I tried using "using Newtonsoft.Json.Linq;" – GET ERROR – Using directive is unnecessary

I was able to reproduce this issue. "Using directive is unnecessary" means that nothing in the current C# code file is referencing a non-namespace qualified type in the namespace of the using directive. This also gets when we only add the using Newtonsoft.Json.Linq; without install it.

In Xamarin.Forms, install the Newtonsoft.Json package from NuGet would fix this error.

  • Related