Create a class which will hold the data from the string.
[DataContract]
public class MyClass
{
[DataMember]
public string key;
[DataMember]
public string value;
}
Include using System.Runtime.Serialization;
Mechanism:
If the original string is in format : {"key-client-post", "value-from-server-side"}, Convert the string to the format : {"key" : "key-client-post", "value" : "value-from-server-side"}
Then use the DataContractJsonSerializer to deserialize the new string.
static void Main(string[] args)
{
String s_key = @"""key"":";
String s_value = @"""value"":";
String text = @"{""key1"", ""value1""}";
String text_new = text.Insert(text.IndexOf('{')+1, s_key);
text_new = text_new.Insert(text_new.IndexOf(',') + 1, s_value);
Console.WriteLine(text_new);
MemoryStream stream1 = new MemoryStream(ASCIIEncoding.Default.GetBytes(text_new));
DataContractJsonSerializer deser = new DataContractJsonSerializer(typeof(MyClass));
MyClass keyValue = (MyClass)deser.ReadObject(stream1);
Console.WriteLine(keyValue.key);
Console.WriteLine(keyValue.value);
}