Answer to Question #189884 in C# for santhosh asrith

Question #189884

Create the array of suppliers and store this collection of suppliers in JSON object using JSON Serialization 


1
Expert's answer
2021-05-06T07:24:09-0400
using System;
using System.Text.Json;

namespace Test
{
    class Supplier
    {
        public Supplier(string name)
        {
            Name = name;
        }

        public string Name { get; private set; }
    }

    class JsonTest
    {
        static int Main()
        {
            Supplier[] suppliers = new Supplier[]
            {
                    new Supplier("Apple"), 
                    new Supplier("Microsoft"), 
                    new Supplier("Intel")
            };

            JsonSerializerOptions options = new JsonSerializerOptions { WriteIndented = true};
            string                json    = JsonSerializer.Serialize(suppliers, options);


            Console.WriteLine(json);

            return 0;
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS