这是我要取的字符串
string source2 = @"{""c"":""run"",""x"":"100"",""y"":""20"",""z"":""0"",""r"":""0"",""v"":""322""}";
我想取x,y,z,r后面的四个值100,20,0,0
要如何取呢?本来想用split,可是也不太行,求指教!
这是我要取的字符串
string source2 = @"{""c"":""run"",""x"":"100"",""y"":""20"",""z"":""0"",""r"":""0"",""v"":""322""}";
我想取x,y,z,r后面的四个值100,20,0,0
要如何取呢?本来想用split,可是也不太行,求指教!
两个办法,一个是用正则匹配,一个是用Newtonsoft第三方json库将这个转成json然后读取
另外,你的这个字符串赋值好像也有问题
string source2 = @"{""c"":""run"",""x"":"**"**100"",""y"":""20"",""z"":""0"",""r"":""0"",""v"":""322""}";
100前少了个双引号
string source2 = @"{""c"":""run"",""x"":""100"",""y"":""20"",""z"":""0"",""r"":""0"",""v"":""322""}";
string x = Regex.Match(source2, @"(?<=""x"":"")\d+").Value;
string y = Regex.Match(source2, @"(?<=""y"":"")\d+").Value;
string z = Regex.Match(source2, @"(?<=""z"":"")\d+").Value;
string r = Regex.Match(source2, @"(?<=""r"":"")\d+").Value;
Hashtable ht = JsonConvert.DeserializeObject<Hashtable>(source2);
string x1 = ht["x"].ToString();
string y1 = ht["y"].ToString();
string z1 = ht["z"].ToString();
string r1 = ht["r"].ToString();