JulioBello-4525 avatar image
0 Votes"
JulioBello-4525 asked Viorel-1 commented

Create a JSON Object Containing a Named Array of Strings

Hi, Everybody! Please see my class below...

     public class PutShipmentsReleaseRequest : BaseRequest
         [DataMember(Name = "ShipmentIds")]
         public string[] ShipmentIds { get; set; } // Mandatory, The tracking number or Unique Id of the shipment to defer

When it is serialized, it looks like this...


I need it to look like this...

{ "ShipmentIds": ["3A02939620000008A1977","3A02939620000008A198D","3A02939620000008A199B","3A02939620000008A19A9"] }

How can I achieve the desired output?

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

It seems to work as expected in case of System.Text.Json.JsonSerializer. How to reproduce the problem?

0 Votes 0 ·

Hi, Viorel...

I am using namespace System.Web.Script.Serialization. It automagically works with the DataContract and the DataMember attributes.

Apparently, I cannot use System.Text.Json.JsonSerializer. I am running .NET 4.6. The JsonSerializer Class applies to .NET 5.0/.NET Core 3.0+.

Upgrading the project to .NET 5.0 is not presently an option due to time constraints. Upgrading a project to a later/latest version of .NET is a project in itself. Perhaps the upgrade can be scheduled in the future.

I would enjoy hearing from you again... Especially if you find a solution for .NET 4.6.

Unless I hear otherwise, I have a hack for this, but I rather stick to "Standard Practices".

Thank-you, Viorel!

Truly grateful.

0 Votes 0 ·

System.Text.Json is available for .NET Framework too and can be installed using “Manage NuGet Packages” command.

If you serialize the object explicitly, then show a short code to reproduce the problem, if possible.

0 Votes 0 ·

0 Answers