M
M
maksam072016-11-20 14:15:53
C++ / C#
maksam07, 2016-11-20 14:15:53

How to solve Cannot access child value on Newtonsoft.Json.Linq.JValue error?

Good day!
I have JSON data, I output it like this:

foreach( var data in JSON ) {
if ( data != null ) {
var count = data["count"];
//дальше код
}
}

Part of the data passes normally, but the program complains about the line
var count = data["count"];
with an error about the smaller part:
Cannot access child value on Newtonsoft.Json.Linq.JValue

If you make a check:
if ( data["count"] != null ) { /* дальше код */ }
Then there will still be an error, but the condition is already indicated.
How is this problem solved? Already climbed a lot of things, but nothing helped.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrew, 2016-11-21
@impwx

If you show your JSON, it will be clearer.
Judging by JValue, in one of your cases datait becomes not an object with nested properties, but a primitive type (for example, a number or a string).
Perhaps this is an error in the formation of the data that you are processing. If you receive data from outside and this situation is acceptable, then instead data["count"] != nullput a check on data is JObject.

S
Svezhka, 2018-09-12
@Svezhka

The point is DPMS (Display Power Management Signaling), which cuts off the monitor in order to save energy.
You can check its operation using xset -q, the output will be something like this:
DPMS (Energy Star):
Standby: 0 Suspend: 0 Off: 0
DPMS is Enabled
Monitor is On
You can disable it with:
xset -dpms; xset s off
( in fact, turn off dpms and screen power saving mode)
* the settings are valid only for the current session, so if you do not need power saving, you can set the command to autoload, or manually execute the command each time at the start of work.

T
TyzhSysAdmin, 2017-02-27
@POS_troi

Screensaver

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question