C
C
continue2015-10-25 21:38:36
C++ / C#
continue, 2015-10-25 21:38:36

"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);

YHiYQIs.png
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
continue, 2015-10-26
@continue

Solution for this problem:

string body = "";
foreach (JToken j in testObject["response"])
{
    if (j is JObject)
    {
        body = (string)j["body"];
    }
}

M
MrDywar Pichugin, 2015-10-25
@Dywar

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.

R
Roman, 2015-10-26
@yarosroman

show original JSON.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question