简体   繁体   English

在 c# 中拆分字符串

[英]Splitting string in c#

I have a string getting posted to my MVC action that looks like this:我有一个string被发布到我的 MVC 操作中,如下所示:

[{"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.在这种情况下,我需要twentyfive的半径值,但可以是任何值,也可以是每个纬度和经度数,所以在这里它们是40.036218-75.51381100000003

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您可以像这样创建 class

public class PropertyValue
{
    public string property {get; set;}
    public string value  {get; set;}
}

and use JavaScriptSerializer并使用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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM