Reputation: 4972
I have a JSON Input and i need to store specific key value from it.
For eg: Lets says, i have input like below
I/P:
{
"CLICKS": "0.14",
"IMPRESSIONS": 0,
"SOCIAL": 0,
"REACH": 0,
"ACTIONS": 0
}
O/P:(In String Form)
{ "CLICKS": "0.14"}
I am using JObject
var finalJsonData = JObject.Parse(jsonInStringForm);
I can try with JToken or SelectToken, but that will make it more complex, thats why looking for more optimized solution or inbuilt feature in C# libs.
Upvotes: 0
Views: 584
Reputation: 12807
Do you want something like this?
JObject input = JObject.Parse(@"{
""CLICKS"": ""0.14"",
""IMPRESSIONS"": 0,
""SOCIAL"": 0,
""REACH"": 0,
""ACTIONS"": 0
}");
JProperty find = input.Property("CLICKS");
JObject output = new JObject(find);
string s = output.ToString();
If you want to remove single property:
JObject input = JObject.Parse(@"{
""CLICKS"": ""0.14"",
""IMPRESSIONS"": 0,
""SOCIAL"": 0,
""REACH"": 0,
""ACTIONS"": 0
}");
JProperty find = input.Property("IMPRESSIONS");
find.Remove();
string s = input.ToString().Dump();
Upvotes: 1
Reputation: 56
Copy your JSON code
{
"CLICKS": "0.14",
"IMPRESSIONS": 0,
Then inside Visual Studio create an class from the pasted JSON data.
"SOCIAL": 0,
"REACH": 0,
"ACTIONS": 0
}Edit -> Paste Special -> Paste JSON as Classes
Upvotes: 0