1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//author mdsaputra.wordpress.com | EtaYuy | Meihta Dwiguna Saputra
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace JsonTutorial
{
    [Serializable]
    public class PosRequest
    {
        public int ammount { get; set; }
        public String requestType { get; set; }
    }
}
And below is how to serialize (convert to JSON) and deserialize (convert to POCO) em :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//author mdsaputra.wordpress.com | EtaYuy | Meihta Dwiguna Saputra
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
 
namespace JsonTutorial
{
    class JsonMessageHandler
    {
        //Serialize
        public static String parseObjectToJson(Object objectToJson)
        {
            return JsonConvert.SerializeObject(objectToJson);
        }
 
        //Deserialize
        public static PosRequest parseJsonToTransactionMessage(String json)
        {
            return JsonConvert.DeserializeObject<PosRequest>(json);
        }
    }
}
Easy isn’t it? Hope the post useful,