C#|从URL获取JSON无法将字符串转换为int

C#|从URL获取JSON无法将字符串转换为int,c#,json,C#,Json,我有一段代码,可以从URL获取信息。获取名为lovel\u price的值,然后将其解析为一个变量,但JSON中有一个$符号,因此我必须将其删除,之后我无法正确解析JSON 我的代码: var tokenPrice = JObject.Parse(steamMarket).ToString().Replace("$", " "); double marketPrice = tokenPrice["lowest_price"]; JSON 错误: 参数1:无法从“string”转换为“int”

我有一段代码,可以从URL获取信息。获取名为
lovel\u price
的值,然后将其解析为一个变量,但JSON中有一个
$
符号,因此我必须将其删除,之后我无法正确解析JSON

我的代码:

var tokenPrice = JObject.Parse(steamMarket).ToString().Replace("$", " ");
double marketPrice = tokenPrice["lowest_price"];
JSON

错误:

参数1:无法从“string”转换为“int”

tokenPrice[“最低价格”]是一个字符串,c#不会自动为您转换类型

var tokenPrice = JObject.Parse(steamMarket);
double marketPrice = double.Parse(tokenPrice["lowest_price"].ToString().Replace("$", ""));
您还可以执行以下操作:

string json = "{\"success\":true,\"lowest_price\":\"$5.61\",\"volume\":\"6\",\"median_price\":\"$5.61\"}";
var jObject = Newtonsoft.Json.Linq.JObject.Parse(json);
double tokenPrice = double.Parse((string )jObject["lowest_price"], NumberStyles.Currency, new CultureInfo("en-US"));

可能的重复项为tokenPrice提供了Replace的值,它是一个字符串。不能使用字符串索引到字符串中。它与原始代码有相同的问题。
var tokenPrice = JObject.Parse(steamMarket);
double marketPrice = double.Parse(tokenPrice["lowest_price"].ToString().Replace("$", ""));
string json = "{\"success\":true,\"lowest_price\":\"$5.61\",\"volume\":\"6\",\"median_price\":\"$5.61\"}";
var jObject = Newtonsoft.Json.Linq.JObject.Parse(json);
double tokenPrice = double.Parse((string )jObject["lowest_price"], NumberStyles.Currency, new CultureInfo("en-US"));