Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JObject missing in .NET core, in NewtonSoft package

I'm trying to load a json file in .NET Core. To do this I'm using the NewtonSoft package. I successfully installed it, and

using NewtonSoft.Json;

produces no compiler errors. However when I try to load and parse a file as per their example, using

JObject obj = JObject.Parse(File.ReadAllText("file.json"));

I get a compiler error, telling me that JObject does not exist. My suspicion is that there is a difference between .NET Framework and .NET Core implementation, but I don't know. In any case how do I load a json file using NewtonSoft?

like image 213
WreckFish Avatar asked Apr 12 '17 22:04

WreckFish


1 Answers

According official docs, JObject class is in Newtonsoft.Json.Linq namespace, so you need another import:

using Newtonsoft.Json.Linq;

JObject obj = JObject.Parse(File.ReadAllText("file.json"));
like image 116
VMAtm Avatar answered Sep 30 '22 16:09

VMAtm