Reputation: 24102
I have a string
getting posted to my MVC action that looks like this:
[{"property":"radius","value":"twentyfive"},{"property":"latlng","value":"40.036218,-75.51381100000003"}]
I need the radius value of twentyfive
in this case, but could be anything, and also each latitude and longitude number, so they would be 40.036218
and -75.51381100000003
here.
so something like:
string filter = "[{\"property\":\"radius\",\"value\":\"twentyfive\"},{\"property\":\"latlng\",\"value\":\"40.036218,-75.51381100000003\"}]";
string radius = //whatever i need to do;
double lat = //whatever i need to do;
double lng = //whatever i need to do;
Thanks!
Upvotes: 1
Views: 133
Reputation: 109027
You can create a class like this
public class PropertyValue
{
public string property {get; set;}
public string value {get; set;}
}
and use JavaScriptSerializer
string inputString = @"[{""property"":""radius"",""value"":""twentyfive""},{""property"":""latlng"",""value"":""40.036218,-75.51381100000003""}]";
IList<PropertyValue> propertyValueList = new JavaScriptSerializer()
.Deserialize<IList<PropertyValue>>(inputString);
Console.WriteLine(propertyValueList.Single(p => p.property == "radius").value);
Upvotes: 4