Deserialize nested json in VB.NET [duplicate] - json

This question already has answers here:
VB.net JSON Deserialize
(3 answers)
Closed 6 years ago.
I am using the json.net library and I have this json file I want to deserialize:
{
"location":"/UndefinedTag/UndefinedPos/1480679543072",
"parameters":{
"SwitchPoint1":{
"SamplingRate":null,
"BitLength":16,
"BitOffset":0,
"DataType":"BooleanT"
},
"SwitchPoint2":{
"SamplingRate":null,
"BitLength":16,
"BitOffset":1,
"DataType":"BooleanT"
},
"SensorValue":{
"SamplingRate":null,
"BitLength":14,
"BitOffset":2,
"DataType":"IntegerT"
}
}
}
can anybody help ?
Thank you

Please read Deserializing complex object using Json.NET first (altough it's C#-related). In your case you need several .NET object types defined beforehand:
"parent" one holding location and parameters properties (where parameters represents collection of "named sensors")
"named sensor" representing each specialized sensor type, such as SwitchPoint1, SwitchPoint2 or SensorValue (where each "named sensor" type contains related "sensor value" property)
"sensor value" holding single sensor properties such as SamplingRate, BitLength, etc.

Related

Powershell: How can I dynamically iterate over nested json objects? [duplicate]

This question already has answers here:
PowerShell iterate through json of key value pairs
(1 answer)
Powershell Selecting NoteProperty Type Objects From Object
(2 answers)
Closed 3 months ago.
Suppose I have something like this:
"config_service": {
"config_service_1": {
"service": "__service1__"
},
"config_service_2": {
"service": "__service2__"
}
},
I am able to grab out the parent json by doing
$jsonMappings.config_service
But how can I dynamically iterate over each json value in there and do something like, for each object within config_service, extract value of key named 'service'? When I try doing ForEach-Object it treats the config service 1 and 2 as one big object.

Jsp use JSON Object with JSTL [duplicate]

This question already has answers here:
How do I use JSTL to output a value from a JSON string?
(1 answer)
Display JSON object using JSP/ JSTL tags in UI? [duplicate]
(1 answer)
How to parse JSON in Java
(36 answers)
Closed 3 years ago.
I know this topic was discussed pretty often and I guess it is not a diffucult thing.
I want to use a JSON Object from my session in a JSP. The Object has the following structur:
{
"addedUsers":[
{
"city":"Los Angeles",
"name":"Doe",
"forname":"John",
"title":"Dr.",
"userId":2
}
],
"allUsers":[
{
"city":"Los Angeles",
"name":"Doe",
"forname":"John",
"title":"Dr.",
"userId":2
},
{
"city":"New York",
"name":"Peter",
"forname":"Parker",
"title":"Dr.",
"userId":3
}
]
}
Now I want to grab the Objects by name for example doing a for each on the "addedUsers" Object and grab the properties. It is important not just to iterate over the whole Object. I have to call them by name.

How to deserialize list with mixed types? [duplicate]

This question already has answers here:
Unmarshal 2 different structs in a slice
(3 answers)
Closed 4 years ago.
How would I deserialize this JSON in Go?
{
"using": [ "jmap-core", "jmap-mail" ],
"methodCalls": [
["method1", {"arg1": "arg1data", "arg2": "arg2data"}, "#1"],
["method2", {"arg1": "arg1data"}, "#2"],
["method3", {}, "#3"]
]
}
I haven't figured out how to properly get the json module to parse the methodCalls into a type. My first idea was
type MethodCall struct {
Name string
Params map[string]string
ClientId string
}
and then to use it as a list type:
type Request struct {
Using []string
MethodCalls []MethodCall
}
But this does not work. :using" is correctly parsed, but the "methocCalls" are not. Is there a way to get Go to parse this JSON into my types?
It looks like the methodCalls that you are trying to deserialize it is an array of strings instead of a struct for MethodCall.
So, Take a look at this link that I am deserializing as an array.
If you want to use the MethodCall struct you have to change the json a little bit. Take a look at this link

from JSON object to Java Script Object that contains js function name [duplicate]

This question already has answers here:
Safely turning a JSON string into an object
(28 answers)
Closed 5 years ago.
I have this JS object:
{ validator: myValidator }
myValidator is a java JAVASCRIPT function NAME that will be declared somewhere else. I am planning to use it like:
<TableHeaderColumn dataField='status' editable={ { validator: myValidator } }>Job Status</TableHeaderColumn>
where TableHeaderColumn is a react component. So, the question is: What is the JSON string that after using JSON.parse or a similar command I will obtain the { validator: myValidator } object where myValidator is "the name of a function", not a string. This is not clear for me inclusive at the referenced solution.
To convert a JS Object to JSON, you can use json = JSON.stringify(jsObject)
To convert JSON to a JS Object, just use jsObject = JSON.parse(json)

Extracting key values across nested JSON [duplicate]

This question already has answers here:
How can I access and process nested objects, arrays, or JSON?
(31 answers)
Closed 9 years ago.
I am trying to extract the values from a nested JSON file that looks like so:
var mymenu = {"menu": [{"page": {"url": "http://foo.bar.com","random stuff": {"junk": "rubbish"}}},{"page": {"feed": "http://foo.bar.com"}},{"menu": [{"submenu": [{"page": {"feed": "http://foo.bar.com"}}]}]}]};
The keys I am trying to extract are the feeds with contain urls. I have tried a for...in loop into the retrieved JSON but I can only get as far as pulling the object that the feed is in resulting in the stringified object as a whole. Is there a way to get just the keys I need from the JSON file?
I just validated your json on JSONLint and it seems to be invalid.
Parse error on line 7:
... } }
----------------------^
Expecting 'STRING'
Try this json, and remember to assign a name to your variable.
var mymenu = {"menu": [{"page": {"url": "http://foo.bar.com","random stuff": {"junk": "rubbish"}}},{"page": {"feed": "http://foo.bar.com"}},{"menu": [{"submenu": [{"page": {"feed": "http://foo.bar.com"}}]}]}]};
Next iterating through the json isn't too bad, just think of it as a multi dimensional array with key value pairs. For instance, if you're running firefox it's a good idea to get firebug.
for(var i = 0; i < mymenu['menu'].length; i)
{
console.log(mymenu['menu'][i]);
}