2011-06-28 22 views
1

に私はstringこのようになります私のMVCのアクションに投稿されたばかりしている:分割文字列は、C#

[{"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; 

ありがとう!

+4

を使用することができます。 –

答えて

4

あなたはこの

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

のようなクラスを作成し、いくつかのJSON.NETを自分でフックアップし、単にオブジェクトにJSON文字列をデシリアライズ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);