use in for each loop CType(jsonObject(“Test111”)(“Test222”),JArray)
Error:- Object reference not set to an instance of an object.
use in for each loop CType(jsonObject(“Test111”)(“Test222”),JArray)
Error:- Object reference not set to an instance of an object.
Hi @shuklarchana001,
Please, take a look at the attached file
Main.xaml (6.3 KB)
If this solves your problem, kindly mark this post as solution to close this topic.
If you need extra help and/or have any question, please let me know
Thanks!
I have tried same but still given same error as earlier I have mention error
Error:- Object reference not set to an instance of an object.
Are you using the json below?
If so and you use the attached file I sent you, it will work properly.
If you are using the real json, I would need to see it (be careful with private data) to identify the error, if possible.
{
"Test111": {
"Test222": [
{
"name": "Test Data123",
"effectiveDate": "2021-09-27T04:01:00Z",
"amt": "$10/$200",
"premium": {
"amount": 0,
"currency": "usd"
},
"code": "sfdsfdf"
},
{
"name": "Test Data123",
"effectiveDate": "2021-09-27T04:01:00Z",
"amt": "$50",
"premium": {
"amount": 0,
"currency": "usd"
},
"code": "ewr",
}]
}
I am using json but same getting error.
I need json array values from json data
real one in my scenario
In this case, not entering in loop , it just skip loop and move
Got it.
I believe some of the items don’t have those properties. So when you try to access documents, for example, it will return null. Then, you try to access the currentTermDocuments of a null, it will throw that exception.
So you need to verify before using an if.
Something like this:
yourItem("result") IsNot Nothing AndAlso yourItem("result")("policy") isNot Nothing AndAlso yourItem("result")("policy")("documents") IsNot Nothing AndAlso yourItem("result")("policy")("documents")("currentTermDocuments") IsNot Nothing
Or you can use nested ifs checking one by one and log something in each else branch if you want
If yourItem(“result”) IsNot Nothing
If yourItem(“result”)(“policy”) isNot Nothing
If yourItem(“result”)(“policy”)(“documents”) IsNot Nothing
If yourItem(“result”)(“policy”)(“documents”)(“currentTermDocuments”) IsNot Nothing
If that solves your problem, let me know and kindly mark the most useful post as solution to close this topic.
If you need extra help and/or have any question, please let me know
Thanks!
For Each: Unable to cast object of type ‘Newtonsoft.Json.Linq.JProperty’ to type ‘Newtonsoft.Json.Linq.JObject’.
Could you send me part of your real json? Just replace private data by fake one, but keep the real structure please
Considering the json below, this code works as expected:
Main.xaml (6.8 KB)
{
"result": {
"policy": {
"documents": {
"currentTermDocuments": [
{
"name": "Test Data123",
"effectiveDate": "2021-09-27T04:01:00Z",
"amt": "$10/$200",
"premium": {
"amount": 0,
"currency": "usd"
},
"code": "sfdsfdf"
},
{
"name": "Test Data123",
"effectiveDate": "2021-09-27T04:01:00Z",
"amt": "$50",
"premium": {
"amount": 0,
"currency": "usd"
},
"code": "ewr",
}
]
}
}
}
}
Yeahhh… I’m glad it worked.
It’s always a pleasure to help community members, @shuklarchana001
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.