嗨我通过调用外部api获得json结果.
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync(url).Result;
if (response.IsSuccessStatusCode)
{
var result = response.Content.ReadAsStringAsync().Result;
var s = Newtonsoft.Json.JsonConvert.DeserializeObject(result);
return "Success";
}
else
{
return "Fail";
}
Run Code Online (Sandbox Code Playgroud)
var s = Newtonsoft.Json.JsonConvert.DeserializeObject(result);我得到的结果是:
{{
"query": "1",
"topScoringIntent": {
"intent": "1",
"score": 0.9978111,
"actions": [
{
"triggered": false,
"name": "1",
"parameters": [
{
"name": "1",
"required": true,
"value": null
},
{
"name": "1",
"required": true,
"value": null
},
{
"name": "1",
"required": true,
"value": …Run Code Online (Sandbox Code Playgroud) 我正在尝试在postgres中创建和使用新数据库.当我尝试使用以下命令加载数据库时:
sudo -u postgres psql
Run Code Online (Sandbox Code Playgroud)
我收到这个错误.
无法将目录更改为"/ home/laptop/Dropbox/js/hw/Has-Many-Relationships":权限被拒绝psql(9.3.13)输入"help"获取帮助.
我试图以root身份更改nautilus中的文件夹权限.当文件夹更改为root(cp和cd /)时,此命令将按预期工作任何想法?
我有这个JSON,我必须反序列化它:
{
"homepage": "http://files.minecraftforge.net/maven/net/minecraftforge/forge/",
"promos": {
"1.10-latest": "12.18.0.2000",
"1.10.2-latest": "12.18.1.2014",
"1.10.2-recommended": "12.18.1.2011",
"1.5.2-latest": "7.8.1.738",
"1.5.2-recommended": "7.8.1.737",
"1.6.1-latest": "8.9.0.775",
"1.6.2-latest": "9.10.1.871",
"1.6.2-recommended": "9.10.1.871",
"1.6.3-latest": "9.11.0.878",
"1.6.4-latest": "9.11.1.1345",
"1.6.4-recommended": "9.11.1.1345",
"1.7.10-latest": "10.13.4.1614",
"1.7.10-latest-1.7.10": "10.13.2.1343",
"1.7.10-recommended": "10.13.4.1558",
"1.7.2-latest": "10.12.2.1147",
"1.7.2-recommended": "10.12.2.1121",
"1.8-latest": "11.14.4.1577",
"1.8-recommended": "11.14.4.1563",
"1.8.8-latest": "11.15.0.1655",
"1.8.9-latest": "11.15.1.1902",
"1.8.9-recommended": "11.15.1.1722",
"1.9-latest": "12.16.0.1942",
"1.9-recommended": "12.16.1.1887",
"1.9.4-latest": "12.17.0.1990",
"1.9.4-recommended": "12.17.0.1976",
"latest": "12.18.1.2014",
"latest-1.7.10": "10.13.2.1343",
"recommended": "12.18.1.2011"
}
}
Run Code Online (Sandbox Code Playgroud)
在这个网站上搜索了很多,我得到了以下代码:
dynamic json = JsonConvert.DeserializeObject<Dictionary<string, string>>(data);
foreach (KeyValuePair<string, string> entry in json["promos"])
{
MessageBox.Show(entry.Key);
MessageBox.Show(entry.Value);
} …Run Code Online (Sandbox Code Playgroud) 我想使用以下方法使用Newtonsoft.Json进行反射:
MyType object = JsonConvert.DeserializeObject<MyType>(jsonString);
Run Code Online (Sandbox Code Playgroud)
这是我的方法不起作用(模糊匹配异常):
Type type = Type.GetType("MyType",false);
Type JSONCovert = typeof(JsonConvert);
MethodInfo deserializer = JSONCovert.GetMethod("DeserializeObject", new Type[] { typeof(String) });
deserializer = deserializer.MakeGenericMethod(type);
var o = deserializer.Invoke(null, new object[] { JsonString });
Run Code Online (Sandbox Code Playgroud) 我需要将以下 Json 字符串转换为 DataTable。
{
"pnr":"1234567890",
"train_num":"12311",
"train_name":"HWH DLIKLK MAI",
"doj":"23-12-2013",
"from_station":
{
"code":"DLI",
"name":"Delhi"
},
"to_station":
{
"code":"KLK",
"name":"Kalka"
}
}
Run Code Online (Sandbox Code Playgroud)
在数据表中我需要显示
train_num
train_name
doj
from_station(name only)
to_station(name only)
Run Code Online (Sandbox Code Playgroud)
到目前为止我所拥有的是,
public class Train
{
public string train_num { get; set; }
public string train_name { get; set; }
public string doj { get; set; }
public from_station from_station { get; set; }
public to_station to_station { get; set; }
}
public class from_station
{
public string code { get; …Run Code Online (Sandbox Code Playgroud) 我正在使用 Google Places API 服务(https://developers.google.com/places/web-service/)根据位置名称获取地点 ID。用户键入一些位置名称,就会出现相关建议,用户可以从中选择并获取地点 ID。我有一个要求,我需要三个文本框和一个按钮。用户输入地名、城市名和地址,然后单击按钮获取 placeId。目前,我没有看到基于多个参数获取地点 ID 的选项。我怎样才能做到这一点?
我正在尝试阅读我的JSON结果.
这是我的JsonResult
public class JsonResult
{
public string ResponseStatus;
public string Status;
public string Remarks;
public string ErrorCode;
public List<Data> data;
}
public class Data
{
public string Status;
public DateTime Date;
public string Number;
public string Amount;
public string Balance;
public string TranId;
public string OPTId;
public string RefId;
}
Run Code Online (Sandbox Code Playgroud)
这是我的JSON结果
{
"ResponseStatus":"1",
"Status":"Success",
"Remarks":"Your recharge has been Pending.",
"ErrorCode":"3",
"Data":
{
"Status":"Pending",
"Date":"2017-02-23T17:22:26.2001954+05:30",
"Number":"9915933511",
"Amount":10.0,
"Balance":137.714,
"TranId":"1126887",
"OPTId":"","RefId":""
}
}
Run Code Online (Sandbox Code Playgroud)
这是我读取结果的代码
var result = JsonConvert.DeserializeObject<List<JsonResult>>(retPKT);
Run Code Online (Sandbox Code Playgroud)
但获得例外..
无法将当前JSON对象(例如{"name":"value"})反序列化为类型'System.Collections.Generic.List`1 [JsonResult …
c# ×5
json ×5
json.net ×5
api ×1
datatable ×1
httpclient ×1
postgresql ×1
reflection ×1
ubuntu-14.04 ×1