Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / How to deserialize a J...
Finance forum
Answered

How to deserialize a JSON string

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);
            

  • LuckSong Profile Picture
    LuckSong 75 on at
    RE: How to deserialize a JSON string

    thanks ,it's working

    have a nice weekend.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 225,783 Super User on at
    RE: How to deserialize a JSON string

    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);

  • Martin Dráb Profile Picture
    Martin Dráb 225,783 Super User on at
    RE: How to deserialize a JSON string in D365fo

    What is the stack trace?

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

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,459 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,783 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans