[英]Splitting string in c#
我有一個string
被發布到我的 MVC 操作中,如下所示:
[{"property":"radius","value":"twentyfive"},{"property":"latlng","value":"40.036218,-75.51381100000003"}]
在這種情況下,我需要twentyfive
的半徑值,但可以是任何值,也可以是每個緯度和經度數,所以在這里它們是40.036218
和-75.51381100000003
。
所以像:
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;
謝謝!
您可以像這樣創建 class
public class PropertyValue
{
public string property {get; set;}
public string value {get; set;}
}
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.