Unable to cast object of type 'newtonsoft.json.linq.jobject' to type 'system.string

Hi @Amrita_Mogali

I have a similar problem. I am able to convert a JSON file to a data table using a local file (see attached “JSON to data table” but when I combine this approach with httpRequest, I get an error “Unable to cast object of type ‘Newtonsoft.Json.Linq.JProperty’ to type ‘Newtonsoft.Json.Linq.JObject’.”

Please will you advise what I am doing wrong.

httpRequest.xaml (11.7 KB)
json to data table.xaml (10.0 KB)inputJson.json (1.3 KB)

Your help would be greatly appreciated.

2 Likes

Hi Tobor,

In the httpRequest.xaml, in the for loop, you had incorrectly mentioned BdecJ as the collection to be iterated. I have changed it to BdecJ.Item(“results”). It now works correctly. I have attached the updated workflow for your reference. Hope this helps.

Regards,
Amrita
httpRequest.xaml (12.2 KB)

2 Likes

Hi @Amrita_Mogali

Thank you. That’s great.

Hi @Amrita_Mogali,

I’m also getting the same error when I try to pass variable in selector.
My problem statement is to click a date on a webpage which is dynamic (Date may change). I want whatever the user will enter, it will click on that date. So I have created a Demo project for that and passed a variable in the selector.

I’m attaching the workflow.

Main.xaml (12.7 KB)

Thanks & Regards,
Gunjan Bhogal

Hi @Amrita_Mogali,

Your help would be highly appreciable. Please let me know at the earliest.

Regards,
Gunjan Bhogal

Hi;

image

You cannot use directly genericValue types inside the selector.

You can either:

  • Change your variables type to “String” (simpler)
  • Inside your selector text, use mDate.Tostring and inside the Selector property, mSelector.Tostring

Cheers

@gunjanbhogal,

The value of mSelector is built incorrectly. You missed the single quotes of mDate. I have corrected it for you as below -

" <html title='Tiger Zinda Hai Movie, Showtimes in Pune &amp; Online Ticket Booking' /><webctrl aaname='*"+mDate+"*' parentid='showDates' tag='DIV' /> "

Regards,
Amrita

Thank you @Amrita_Mogali and @Florent_Salendres.

I was able to build selector using a variable with you help, but I had to change the format of mDate in the selector as ‘“+mDate.toString+”

Regards,
Gunjan Bhogal

Hi Amrita ,

I am getting the below exception for Deserialize json activity in uipath , the same use to work fine earlier but now i am getting this error , can you please help me with this
Message: Method ‘Newtonsoft.Json.Linq.JToken get_Item(System.String)’ declared on type ‘Newtonsoft.Json.Linq.JObject’ cannot be called with instance of type ‘Newtonsoft.Json.Linq.JObject’

Exception Type: ArgumentException

Thanks,
Manasa

2 Likes

I may have found of cause of such exception. Did you ever install any custom packages that contains any Newtonsoft.Json references?

This may have caused some issue. Once I have un-install my custom package that references the Newtonsoft.Json dll, I can now retrieve JSON value as normal.

I’m facing the same problem with deserialize json object/array.

Here are the json file (I hope the format is correct…) and the workflow I made.
config.json (21 Bytes)
1.1.loadConfig.xaml (8.0 KB)
I first tried with arguments and then variables but naturally it didn’t make any difference.
Aslo tried uninstalling all the activity packages, but it did not help either.

config.json (101 Bytes)
1.1.loadConfig.xaml (8.1 KB)

Now this works.
Seems like the “¥” I put in the json file was one of the problems I had.

I am trying to pass dynamic value in selector for selecting column name, using input dialog box. But, when I am trying to pass I am getting exception: Invalid Cast Exception

My Selector is : “<webctrl parentid=‘logout’ tableCol=”+dropDate+“tag=‘IMG’ />” Where dropDate is the output I am getting from input dialog box.

Hey @Anchal_Sarraf

What kind of datatype of your passed Input box output argument?

you can use like this:

“<webctrl parentid=‘logout’ tableCol='”+dropDate.Tostring+“' tag=‘IMG’ />”.

Regards,!!
aksh

I am not able to upload my .xaml file, as I am a new user. Is there a way to do that?

TransportDropAutomation.xaml (22.0 KB)

Hello Akash,

I am facing the issue at “Click ‘A logout’” activity.

Regards,
Anchal Sarraf

TransportDropAutomation.xaml (21.9 KB)
I just made the changes what @aksh1yadav told.
Try if this works and please let me know if it did!

Hello Niket,

Thanks for taking out time to check this. I ran this, but still, it is showing invalid selector. What I am trying to do is, I recorded the sequence of scheduling drop by pointing at pencil at one of these coloum. It was working fine. But I want it to be dynamic and ask me column value for which I want to schedule drop. Any other way to automate my drop process?

Hi! I made some changes!


See that there are 9 columns and the column in which pencil exists are starting from Column 7.
So the range of input dialog should be from 7 to 9. I have attached the workflow:
TransportDropAutomation.xaml (21.0 KB)

I hope this works for you! Tell me if it does!

1 Like

Hello Niket,

Thanks a lot, it worked perfectly fine. Though pencil is not showing for others, as I tried to put drop in them but later cancelled as I can’t leave them as it is. Pencil will start from 3 column itself. So as per I can identify after watching workflow, it was the delay which was required apart from what was suggested by Akash above. Is there anything which I was missing.

I am quite new to UiPath, just completed RPA foundation developer training. Trying to use my knowledge by automating daily life activities.

1 Like