Error Reading Jobject From Jsonreader
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of c# error reading jobject from jsonreader this site About Us Learn more about Stack Overflow the company Business
Jobject Parse Error
Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask error reading jobject from jsonreader. current jsonreader item is not an object Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign error reading jobject from jsonreader. path '' line 0 position 0 up JSON.Net error reading up vote 26 down vote favorite 6 I'm trying to parse some JSON data with Json.Net. Here is my data: [ { "UIDClan": "1", "UIDKnjiga": "1", "Naslov": "Title1", "DatumZaKada": "2013-08-09 00:00:00", "DatumIstekRez": null, "Spremno": "0" }, { "UIDClan": "1", "UIDKnjiga": "2", "Naslov": "Title2", "DatumZaKada": "2013-08-08 00:00:00", "DatumIstekRez": null, "Spremno": "0" }, { "UIDClan": "1", "UIDKnjiga": "3", "Naslov": "Title3", "DatumZaKada":
Error Reading Jtoken From Jsonreader
"2013-08-09 00:00:00", "DatumIstekRez": "2013-10-09 00:00:00", "Spremno": "1" } ] With this piece of code i want to extract UIDClan data: JObject o = JObject.Parse(s); Console.WriteLine(o["UIDClan"]); The error is Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1. I've checked with JSONLint and it's valid. The examples that I found doesn't start with [. Am I doing something wrong? json.net share|improve this question edited Jul 13 at 21:24 mikeTheLiar 2,58672848 asked Sep 8 '13 at 20:18 Josef 75341126 add a comment| 1 Answer 1 active oldest votes up vote 58 down vote accepted You could try using a JArray. This JSON data is actually an array. JArray v = JArray.Parse(s); To get the first item. var firstItem = v[0]["UIDClan"].ToString(); You can even use linq var items = v.Where(x => x["UIDClan"].ToString() == "1").ToList(); share|improve this answer edited Sep 8 '13 at 20:41 answered Sep 8 '13 at 20:25 scartag 13.3k32442 Thanks a lot! This is it. Cheers! –Josef Sep 8 '13 at 20:56 what if my object was just a single string? JObject.parse fails
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers error reading jobject from jsonreader betternet or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question error reading jobject betternet x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them;
Betternet Error
it only takes a minute: Sign up Error while using Newtonsoft.Json to parse a Json string up vote 8 down vote favorite My JSON string looks like this. Please note that it has escape characters. string json = "\"{\\\"Status\\\":true,\\\"ID\\\":24501}\""; When http://stackoverflow.com/questions/18688261/json-net-error-reading I use the Parse method like below I run into an error stated below: JObject o = JObject.Parse(json); Error reading JObject from JsonReader. Current JsonReader item is not an object: String How do I get rid of this error or is there any other method to parse my json string and fetch the values? json parsing json.net share|improve this question edited Aug 15 '11 at 21:35 Joe 47.2k1083114 asked Aug 15 '11 at 21:34 SVI 65621126 no answer http://stackoverflow.com/questions/7071086/error-while-using-newtonsoft-json-to-parse-a-json-string of this, m facing the same prob –Mayur Jul 2 '12 at 13:00 add a comment| 5 Answers 5 active oldest votes up vote 4 down vote Remove first and last quotes: string json = "{\"Status\":true,\"ID\":24501}"; See the Json format here. share|improve this answer answered Aug 15 '11 at 21:35 MByD 98k17184213 add a comment| up vote 2 down vote It seems like your object is double encoded. Try: string json = "{\"Status\":true,\"ID\":24501}"; share|improve this answer answered Aug 15 '11 at 21:37 Joe 47.2k1083114 4 That json string is what I get from an API. How do I remove the escape characters?\ –SVI Aug 15 '11 at 21:48 2 @SVI : I'm late to the party but if anybody needs it, just replace them using something like json.Replace("\\\\", "\\") –SolarBear Sep 24 '12 at 19:23 add a comment| up vote 1 down vote You need something like this json = json.Replace(@"\", string.Empty).Trim(new char[]{'\"'}) share|improve this answer answered Jun 22 '15 at 4:16 Samuel 961213 add a comment| up vote 0 down vote in here format should be something like this: string jsonNew = @"{'Status': True,'ID': 24501 }"; share|improve this answer answered May 8 '14 at 6:13 DevT 2,212113868 add a comment| up vote 0 down vote As SolarBear says in his comment, the problem is double-escaping. To get the proper format, like this: string json = "{\"Status\":true,\"ID\":24501}"; Do something like this: json = json.Replace("\\\\", "\\");
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the http://stackoverflow.com/questions/36388616/error-during-json-parsing company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million https://social.msdn.microsoft.com/Forums/sqlserver/en-US/e6bc824c-5230-4eb9-8109-3374ffff7c4d/visual-studio-error-when-opening-project-nuget-manager?forum=visualstudiogeneral programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error during JSON parsing up vote 0 down vote favorite JSON string: [{"id":"1","username":"admin","password":"anymd5hash","rank":"2"}] following code: Newtonsoft.Json.Linq.JObject userData; userData = Newtonsoft.Json.Linq.JObject.Parse(result); error reading MessageBox.Show(userData["username"].ToString()); When I execute this code, there will be an error: Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1. I'm pretty sure, that this code has worked in another project. What is my mistake? c# json json.net share|improve this question edited Apr 3 at 17:29 Uwe Keim 22.6k25100159 asked Apr 3 at 17:22 Reese 1267 3 Remove the [ and ] error reading jobject from your string and try again. It's an array. –Ian Mercer Apr 3 at 17:26 3 Or more likely, switch to Newtonsoft.Json.Linq.JArray.Parse. That will accept your existing input. JToken would also work for either arrays (what you've got) or objects. –Matthew Haugen Apr 3 at 17:28 Thank you both. –Reese Apr 3 at 17:35 1 If you don't know in advance if the root object is an array or object, use JToken.Parse(). –dbc Apr 3 at 17:52 add a comment| 1 Answer 1 active oldest votes up vote 3 down vote You are not providing a Json object, you are providing a Json Array with a single object inside it: // Json object: { "id": "1", ... } //Json array: [ { "id": "1", ... } ] So, either you change the json or the Json.Net code (and look for JArray as in the comments). BTW, if you know the properties in advance you really should create a .Net class to be used to contain the deserialization. public class UserData { public string id { get; set; } public string username { get; set; } public string password { get; set; } public string rank { get; set; } } // and then, in your code: List>(result); share|improve this answer answered
(Русский)ישראל (עברית)المملكة العربية السعودية (العربية)ไทย (ไทย)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語) HomeLibraryLearnDownloadsTroubleshootingCommunityForums Ask a question Quick access Forums home Browse forums users FAQ Search related threads Remove From My Forums Answered by: Visual Studio Error when opening project nuget manager Visual Studio Development > Visual Studio General Questions Question 0 Sign in to vote Hi I encounter the following error message, when I want to open the nuget manager for a project in my solution: An error occurred while reading file '