开发者

Splitting string in c#

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 the开发者_高级运维y 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!


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜