Как написать веб-ответ JSON - PullRequest
0 голосов
/ 06 июня 2018

Здравствуйте, я написал класс сериалайзера Json, и он отлично работает на консоли.Но как я могу отправить JSON ответ на мой веб-API.Для примера я хочу увидеть запрос на моем веб-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; }

    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...