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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to deserialize a JSON string

(0) ShareShare
ReportReport
Posted on by 75

i have a josn str, when i deserializeObject i got the error"The type of object cannot be set.

[DataContractAttribute]
class RPS_SF_Product_Response
{
    real  totalSize;
    boolean done;
    List  records;

    [DataMemberAttribute('totalSize')]
    public real parmtotalSize(real _totalSize = totalSize)
    {
        totalSize = _totalSize;
        return totalSize;
    }

    [DataMemberAttribute('done')]
    public boolean parmdone(boolean _done = done)
    {
        done = _done;
        return done;
    }

    [DataMemberAttribute('records'), DataCollectionAttribute(Types::Class, classStr(RPS_SF_ProductLine_Response))]
	public List parmrecords(List _records = records)
    {
        records = _records;
        return records;
    }

}



[DataContractAttribute]
class RPS_SF_ProductLine_Response
{
    str Id;
    str Name;
    str ProductCode;

    [DataMemberAttribute('Id')]
    public str parmId(str _Id = Id)
    {
        Id = _Id;
        return Id;
    }

    [DataMemberAttribute('Name')]
    public str parmName(str _Name = Name)
    {
        Name = _Name;
        return Name;
    }

    [DataMemberAttribute('ProductCode')]
    public str parmProductCode(str _ProductCode = ProductCode)
    {
        ProductCode = _ProductCode;
        return ProductCode;
    }

}


productCheck={
	"totalSize": 2,
	"done": true,
	"records": [{
		"Id": "01t5C000006BiJQQA0",
		"Name": "All-Purpose Whipped Topping For Bread, Pastry and Cake (Avos",
		"ProductCode": "01314"
	}, {
		"Id": "01t5C000006BiK5QAK",
		"Name": "All-Purpose Whipped Topping For Bread, Pastry and Cake (Avos",
		"ProductCode": "01314"
	}]
}


	RPS_SF_Product_Response  Product_Response;
            Product_Response =  FormJsonSerializer::deserializeObject(classNum('RPS_SF_Product_Response'),  productCheck);
            

  • Martin Dráb Profile Picture
    240,831 Most Valuable Professional on at

    What is the stack trace?

    By the way, let me move your question to a D365FO forum.

  • Verified answer
    Martin Dráb Profile Picture
    240,831 Most Valuable Professional on at

    I fixed your code so I can run it and it successfully parses the JSON string. Please try in your environment:

    str productCheck = @'{
    "totalSize": 2,
    "done": true,
    "records": [
        {
            "Id": "01t5C000006BiJQQA0",
            "Name": "All-Purpose Whipped Topping For Bread, Pastry and Cake (Avos",
            "ProductCode": "01314"
        },
        {
            "Id": "01t5C000006BiK5QAK",
            "Name": "All-Purpose Whipped Topping For Bread, Pastry and Cake (Avos",
        "ProductCode": "01314"
        }
    ]}';
    
    RPS_SF_Product_Response response = FormJsonSerializer::deserializeObject(classNum(RPS_SF_Product_Response), productCheck);

  • LuckSong Profile Picture
    75 on at

    thanks ,it's working

    have a nice weekend.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 495 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 432 Super User 2026 Season 2

#3
CU10121822-0 Profile Picture

CU10121822-0 366

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans