1

Hello I wrote a Json serilaizer class and its working perfect on console. But how can I send json response to my web api . For an example I want see the request on my web api.

localhost:8091/api/account

public class SerilaizeController : ApiController
{
    //Serialized Json: {"name":"fxstar.eu","id":888,"data": 
    [{"positionId":"123","symbol":"GBPJY","timestamp":"16463728"}, 
    {"positionId":"987","symbol":"HJEAC","timestamp":"9966824"}]}
     static void Main(string[] args)
    {
        // Add references
        //First position
        Position p1 = new Position();
        p1.positionId = "123";
        p1.symbol = "GBPJY";
        p1.timestamp = "16463728";

        /*
        //Second Positions
        Position p2 = new Position();
        p2.positionId = "987";
        p2.symbol = "HJEAC";
        p2.timestamp = "9966824";
        */
        //Create List with all positions
        List<Position> List = new List<Position>();
        List.Add(p1);
        //List.Add(p2);


        // Create allPositions
        AllPositions pos = new AllPositions();
        pos.name = "fxstar.eu";
        pos.id = 888;
        pos.data = List;

        //Serialize class to json string
        string Json = JsonConvert.SerializeObject(pos);
        Console.Write(Json);
        Console.Read();
    }

    public class Position
    {
        public string positionId { get; set; }
        public string symbol { get; set; }
        public string timestamp { get; set; }

    }
    public class AllPositions
    {
        public string name { get; set; }
        public int id { set; get; }
        //list all positions
        public List<Position> data { get; set; }

    }
}
derloopkat
  • 6,232
  • 16
  • 38
  • 45
S4YOKAN
  • 11
  • 1
  • and sorry for bad english :) – S4YOKAN Jun 06 '18 at 10:45
  • 1
    Possible duplicate of [How do I make calls to a REST api using c#?](https://stackoverflow.com/questions/9620278/how-do-i-make-calls-to-a-rest-api-using-c) – SᴇM Jun 06 '18 at 10:51

0 Answers0