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)

Json array

(0) ShareShare
ReportReport
Posted on by

I am working with ax data entity using Json.

I try to push a list of records to AX data base using Json array shown below  but the below error is faced 

 Json array:

[{"Key1":"Value1","Key2":Value } ,
{"Key1":"Value1","Key2":Value }]

Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray

the question is how to pass a Json array 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    Please make sure you give us enough information; now I'll have to make quite a few assumptions.

    I assume you're talking about a custom service which accepts a single argument of type array. And I assume the JSON string above is what you're trying to send to the service.

    If so, your message isn't correct. Instead of using an array directly, you should provide an object with one property (with the same name as the name of the method argument). The value of the property will be the array.

  • maram fraij Profile Picture
    on at

    Below  the code I use , the string json include the format of the array above

    string json ; //formatted string

    var data = Encoding.UTF8.GetBytes(json);

    request.ContentLength = json.Length;

    request.ContentType = "application/json";

    var newStream = request.GetRequestStream();

    newStream.Write(data, 0, data.Length);

    newStream.Close();

    var result = request.GetResponse();

  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    Did you at least try my solution?

  • maram fraij Profile Picture
    on at

    I do not understand (you should provide an object with one property (with the same name as the name of the method argument)

    My question is where I have to provide the object  and also what do you mean by (with the same name as the name of the method argument)

  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    Today you added a comment on my blog, but it seems you didn't read previous discussion. My explanation is there just above your comment. Let me copy it here for you:

    I think you’re forgetting to identify the parameter.
    If your parameter is int x, JSON will be { x: 2 }. If your parameter is List x, JSON will be { x: [ … ] }.
    Therefore your actual JSON will be something like { startArray: [{ a : 2, b : 5 },{ a : 1, b : 3 },{ a : 9, b : 4 }]}.

  • Hatem.Mahdy Profile Picture
    10 on at

    We tried your suggested solution, but this error appears:

    "The property 'startArray' does not exist on type 'Microsoft.Dynamics.DataEntities.PayTimeRegister'. Make sure to only use property names that are defined by the type."

    And, as I know that StartArray refers to the JsonToken "[" , and EndArray refers to "]"

    Note that your code is working prefect when we are sending a single item . but we need to send array of items at once.

  • maram fraij Profile Picture
    on at

    Hi Martin

    From AX point of view, each parameter is a field in AX data entity , is there any property on the data entity itself or data entity field  to make it accept posting a list of records

  • Suggested answer
    Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    Sorry, I thought you're talking about a custom service when you commented on my blog about custom services; it seems you actually mean an OData service.

    I don't bother writing JSON string manually so I don't know the answer on the top of my head, but let me teach you how you can get it. Download the sample OData application from GitHub. Using the classes to do what you want, execute and observe the JSON sent to AX. And you're done.

  • Jie G Profile Picture
    on at

    You may consider to Serialize the Json string and then use it to have a try. And as Martin mentioned, you can look at the Json string sending to Ax server using the demo. You can make use of develop tools in browser or Fiddler.

  • maram fraij Profile Picture
    on at

    Hi Martin,

    WebRequest  is used  and we try the idea used in the link below method (JsonServiceGroup1EchoContractListTest) , but unfortunately it does not work  

    The  serialized json string is as the following:

    {"input":[{   XXXXXX  }]},, XXXXXX   indicates our data entity properties .

    The system does not accept "input" string at the beginning of the array.

    github.com/.../ServiceGroup1Tests.cs

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