web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Traversing through elements in JArray

(0) ShareShare
ReportReport
Posted on by 11,633

Hi All,

I have developed a custom service and one of the parameter in my custom service is of type ArrayList. I am using service sample provided by Microsoft to call my custom service and passing ArrayList object. The list comes as ArrayList and I am able to assign it to ArrayList object in my service class. Until here it works fine, but when I am trying to assign the element in the list (i.e. Array of string values) to System.String [] variable, I am getting following exception :

Unable to cast object of type 'Newtonsoft.Json.Linq.JArray' to type 'System.String[]'

To resolve this, I declared a variable of type JArray and used the following code snippet:

while (listEnumerator.MoveNext())
{
jsonArray = new Newtonsoft.Json.Linq.JArray();

jsonArray = listEnumerator.Current;

I am getting the values in jsonArray variable, but just unable to traverse through each value in Array. There are six elements in the array and I want to retrieve all the values to use it in a different process in my service class.

Any clue how to achieve this ?

Thanks,

Baber.

*This post is locked for comments

I have the same question (0)
  • syed baber Profile Picture
    11,633 on at

    And here is the JSON request:

    { "_inventLocationIdFrom": "9339", "_inventLocationIdTo": "9175", "_listOfTransferOrderLine": [ [ "40416", "000873", "Joseph ", "9f640402-8e27-49d2-93a1-d84827e99401", "crm", "1" ] ], "_notes": "", "_shipDate": "2017-08-25" }

    As you can see the fourth parameter is the list of Array.

    Thanks,

    Baber.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans