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


#1

When try to select an item M&E , i am getting an error " unable to cast object of type ‘newtonsoft.json.linq.jobject’ to type 'system.string"

This issue is causing only when i have Ambersent(&) in a list box.
Is there any way to select an item containing of ‘&’


#2

Hi Satish,

Is it a web application you are trying to automate? And is the control a dropdown or listbox?
Could you please share the URL where you are trying to do this if you can? And please do share your xaml file.

We might try to use the HttpUtility.UrlDecode() Or URLEncode Method after checking what the values in the listbox or dropdown are.

Regards,
Amrita


#3

Thank Amrita, I was able to figure workaround by replacing’&’ with ‘*’


#4

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.


#5

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)


#6

Hi @Amrita_Mogali

Thank you. That’s great.


#7

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


#8

Hi @Amrita_Mogali,

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

Regards,
Gunjan Bhogal


#9

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


Getting error in invoke method
#10

@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


#11

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


#12

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


#13

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.


#14

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.


#15

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.


#16

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.


#17

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


#18

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


#19

TransportDropAutomation.xaml (22.0 KB)

Hello Akash,

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

Regards,
Anchal Sarraf


#20

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!