I’m trying to Parse a JSON file which has children of children but I’m getting the below error. Any help would be greatly appreciated.
Error = For Each: Cannot cast Newtonsoft.Json.Linq.JProperty to Newtonsoft.Json.Linq.JToken.
Not sure where JProperty is coming from…
Main.xaml
(37.3 KB)
@Waterfowl_Waterfowl_hunte
As per error looks like what you used in assign is what you need to use in assign…but you are using selecttokens for a jproperty type which is failing
Cheers
delete and retype the statement within the IN field
cross check afterwards the typeargument
we prototyped it with a dummy json (as we cannot rely to yours) and it was returning datatype (JObject)
Thank you for the reply,
*I deleted and retyped the statement with in the IN filed as you suggested.
Im sorry but i am fairly new to UiPath and coding in general so im not 100% sure what “cross check afterwards the typeargument” means. if you could give me some more details i would appreciate it.
i ran the bot and now i’m receiving a slightly new error. not sure if this is because i didnt know how to cross check type arguments.
New Error - For Each: Cannot cast Newtonsoft.Json.Linq.JArray to Newtonsoft.Json.Linq.JToken.
I also provided the JSON in case it could help.
json.txt
(2.6 KB)
please tell us
which version of UiPath.WebApi.Activities is referenced within your project
feel free to upgrade to newer versions, when not using the latest one
Version of UiPath.System.Activities
So looks like im using versions
*UiPath.WebAPI.activties - 1.16.2 (i think newer then whats in your screen shot).
*UiPath.System.Activities - 20.10.6 (i think older) would you recommend me upgrading?
Im not sure this is correct. i didnt make any changes between nwa and lineitem. i double checked the screen shots. please correct me if im wrong. the outer ForEach is line item and the inner ForEach is nwa
Shoot, not sure how that change happened. I changed it back to item.SelectTokens(“nwa”).Values(Of Jobject)
Now i’m getting the ‘For Each: Cannot cast Newtonsoft.Json.Linq.JProperty to Newtonsoft.Json.Linq.JToken’ error
line_items is a property of your JObject and its value is JArray with item(s) of JObject
So we loop with
Json2("line_items").Values(Of JObject)
← Value
s
s due Plural as an JArray can have multiple items
"nwa": {
"network": "100001745575",
"activity": "0020",
"name": "63-1W63-B-1-5 SECURITY FEATURES"
nwa is a property of your looped JObject (loop variable name: item) and its value is a JObject.
So nothing to loop, we access directly by
item(“nwa”)(“network”).Value(Of String)
item(“nwa”)(“activity”).Value(Of String)
Good Morning,
I replicated your sequence. but im getting a “Option Strict On Disallows late Binding” error. i have been trying different things for about an hour to remove the error with no joy.
I did try .ToString and not .value(of String) but received the same error
Any Thoughts?
Waterfowl_Waterfowl_hunte:
Thank you for your time and patience. I have learned a lot in this conversation.
Perfect so we can close the topic by marking the helping answer:
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum
Log In using your UiPath Account to:
• get help with your automation projects
• share feedback, report bugs or just drop us any question
• become an MVP and get access to
exclusive events
• save your user preferences like themes and more
• automatically sign in to other services
• get in touch with our Forum staff