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 :
Finance | Project Operations, Human Resources, ...
Unanswered

Parsing json getting error

(0) ShareShare
ReportReport
Posted on by 29

This is the json Im trying to parse. I required 3 field only from this Json (valid, businessNumberType,exemptionReason.Name) but Im getting the error The type of object cannot be set.

{
"@recordsetCount": 1,
"value": [
{
"id": 1,
"companyId": 1,
"customerCode": "0102AGTUR001",
"name": "Test Customer",
"attnName": "Vern Jorgensen",
"line1": "26516 Dineral",
"city": "Mission Viejo",
"postalCode": "92691",
"phoneNumber": "555-555-5555",
"faxNumber": "444-444-4444",
"emailAddress": "someone@gmail.com",
"contactName": "Vern Jorgensen",
"createdDate": "2019-06-13T22:48:48",
"modifiedDate": "2023-03-02T22:23:25.799417",
"country": "US",
"region": "CA",
"isBill": false,
"isShip": false,
"certificates": [
{
"id": 909,
"signedDate": "2016-02-01",
"expirationDate": "2020-12-31",
"filename": "50afc677-8632-4a21-9fe1-45dafb1bb664",
"documentExists": false,
"valid": true,
"verified": false,
"exemptPercentage": 0.0,
"isSingleCertificate": false,
"exemptionNumber": "Exempt-1234",
"validatedExemptionReason": {
"id": 19,
"name": "EXPOSURE: EXPIRED CERT"
},
"exemptionReason": {
"id": 70,
"name": "RESALE"
},
"status": "COMPLETE",
"createdDate": "2021-03-24T06:42:00",
"modifiedDate": "2021-03-24",
"taxNumberType": "FEIN",
"businessNumberType": "Business Services",
"pageCount": 0,
"exposureZone": {
"id": 89,
"name": "Washington",
"tag": "EZ_US_WA"
}
}
]


}
]
}

Runnable class

Class Test
{

Public static void main(Args _args)
{
//call the APi

output = streamRead.ReadToEnd();

TestJSONDataContract TestJSONDataContract = FormJsonSerializer::deserializeObject(classNum(TestJSONDataContract),output);// IineCont getting the error
}
}

My Contract classes

//TestJSONDataContract only one contract method
[DataContract]
Class TestJSONDataContract
{
[DataMemberAttribute('value'),DataCollectionAttribute(Types::class, classStr(JsonObjectDataContract))]
public List parmValue(List _value = value)
{
value = _value;
return value;
}
}

[DataContract]
Class JsonObjectDataContract
{
[DataMemberAttribute("certificates"),
DataCollectionAttribute(Types::Class, classStr(CustomerCertContract))]
public List parmCertificates(List _certificates = certificates)
{
certificates = _certificates;
return certificates;
}
}

[DataContract]
Class CustomerCertContract
{
[DataMember("valid")]
public boolean parmValid(boolean _valid = valid)
{
valid = _valid;
return valid;
}

[DataMember("businessNumberType")]
public str parmBusinessNumberType(str _businessNumberType = businessNumberType)
{
businessNumberType = _businessNumberType;
return businessNumberType;
}
}

Please help me where I am going wrong

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

    Could you please paste code with indentation (through Insert > Code) and mention your version of AX?

    Line indentation makes code much easier to follow. You can even enable syntax highlighting for JSON (not X++, unfortunately).

  • MuthukumaranAX Profile Picture
    2,903 on at

    You can check the below link, might help to resolve the issue

    allaboutdynamic.com/.../

  • Vishnu@94 Profile Picture
    29 on at

    Class Test
    {
    
    public static void main(Args _args)
    {
    //call the APi
    
    output = streamRead.ReadToEnd();
    
    TestJSONDataContract TestJSONDataContract = FormJsonSerializer::deserializeObject(classNum(TestJSONDataContract),output);// IineCont getting the error
    }
    }
    
    //Contract class
    [DataContract]
    Class TestJSONDataContract
    {
    [DataMemberAttribute('value'),DataCollectionAttribute(Types::class, classStr(JsonObjectDataContract))]
    public List parmValue(List _value = value)
    {
    value = _value;
    return value;
    }
    }

    Class CustomerCertContract
    {
    [DataMember("valid")]
    public boolean parmValid(boolean _valid = valid)
    {
    valid = _valid;
    return valid;
    }
    
    [DataMember("businessNumberType")]
    public str parmBusinessNumberType(str _businessNumberType = businessNumberType)
    {
    businessNumberType = _businessNumberType;
    return businessNumberType;
    }
    }

  • Vishnu@94 Profile Picture
    29 on at

    Hi Martin I have formatted the code now Could you please have a look into that. Is it required to put all the fields in the JSON to the contract class.

  • Vishnu@94 Profile Picture
    29 on at

    MuthukumaranAX  I tried the above way but still Im getting the error.

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

    Your code still lacks line indentation. It should look like this:

    {
      "@recordsetCount": 1,
      "value": [
        {
          "id": 1,
          "companyId": 1,
          "customerCode": "0102AGTUR001",
          "name": "Test Customer",
          "attnName": "Vern Jorgensen",
          "line1": "26516 Dineral",
          "city": "Mission Viejo",
          "postalCode": "92691",
          "phoneNumber": "555-555-5555",
          "faxNumber": "444-444-4444",
          "emailAddress": "someone@gmail.com",
          "contactName": "Vern Jorgensen",
          "createdDate": "2019-06-13T22:48:48",
          "modifiedDate": "2023-03-02T22:23:25.799417",
          "country": "US",
          "region": "CA",
          "isBill": false,
          "isShip": false,
          "certificates": [
            {
              "id": 909,
              "signedDate": "2016-02-01",
              "expirationDate": "2020-12-31",
              "filename": "50afc677-8632-4a21-9fe1-45dafb1bb664",
              "documentExists": false,
              "valid": true,
              "verified": false,
              "exemptPercentage": 0,
              "isSingleCertificate": false,
              "exemptionNumber": "Exempt-1234",
              "validatedExemptionReason": {
                "id": 19,
                "name": "EXPOSURE: EXPIRED CERT"
              },
              "exemptionReason": {
                "id": 70,
                "name": "RESALE"
              },
              "status": "COMPLETE",
              "createdDate": "2021-03-24T06:42:00",
              "modifiedDate": "2021-03-24",
              "taxNumberType": "FEIN",
              "businessNumberType": "Business Services",
              "pageCount": 0,
              "exposureZone": {
                "id": 89,
                "name": "Washington",
                "tag": "EZ_US_WA"
              }
            }
          ]
        }
      ]
    }

    (I used json-indent.com to fix indentation.)

    class Test
    {
    	public static void main(Args _args)
    	{
    		//call the APi
    
    		output = streamRead.ReadToEnd();
    
    		TestJSONDataContract testJSONDataContract = FormJsonSerializer::deserializeObject(classNum(TestJSONDataContract), output);// IineCont getting the error
    	}
    }
    
    //Contract class
    [DataContract]
    class TestJSONDataContract
    {
    	[	DataMemberAttribute('value'),
    		DataCollectionAttribute(Types::class, classStr(JsonObjectDataContract))]
    	public List parmValue(List _value = value)
    	{
    		value = _value;
    		return value;
    	}
    }
    
    [DataContract]
    class JsonObjectDataContract
    {
    	[	DataMemberAttribute("certificates"),
    		DataCollectionAttribute(Types::Class, classStr(CustomerCertContract))]
    	public List parmCertificates(List _certificates = certificates)
    	{
    		certificates = _certificates;
    		return certificates;	
    	}
    }
    
    class CustomerCertContract
    {
    	[DataMember("valid")]
    	public boolean parmValid(boolean _valid = valid)
    	{
    		valid = _valid;
    		return valid;
    	}
    
    	[DataMember("businessNumberType")]
    	public str parmBusinessNumberType(str _businessNumberType = businessNumberType)
    	{
    		businessNumberType = _businessNumberType;
    		return businessNumberType;
    	}
    }

    Won't you get more details about the problem if you debug FormJsonSerializer?

    Please tell us which version of AX you're using. It seems that it's either AX 2012 (and we need to update the version tag), or it's actually about F&O (and I'll move it to Dynamics 365 Finance Forum).

  • Vishnu@94 Profile Picture
    29 on at

    I got the solution Thanks martin

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 456 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans