Answer the question
In order to leave comments, you need to log in
"System.InvalidOperationException" in Newtonsoft.Json.dll - C#?
Good day. I can not understand why the program is running crookedly.
JObject testObject = JObject.Parse(resultPage);
int userCount = (int)testObject["response"].Count();
string usersList = "";
for (int i = 0; i < userCount; i++)
{
usersList += (i + 1).ToString() + ". " +
testObject["response"][i]["body"] + ")\r\n";
}
Console.WriteLine(usersList);
Answer the question
In order to leave comments, you need to log in
Solution for this problem:
string body = "";
foreach (JToken j in testObject["response"])
{
if (j is JObject)
{
body = (string)j["body"];
}
}
InvalidOperationException - if correctly defined, means that you are trying to perform an operation that is not available.
To solve the problem and figure it out yourself, you can download the free Free .NET Decompiler and Assembly Browser .
Decompile the dll as a project or file and include it in your project.
This way you will find exactly where and why the exception you see is being thrown.
Or google the doc and DLL examples. clearly a bug.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question