我几周前开始使用C#进行编程工作,我试图从大量数据中提取一些信息,实际上是通过GET / POST http请求收集的。
到目前为止,我没有遇到任何问题,但我现在正在努力解决这个困难,我相信你的眼睛看起来很荒谬。这就是为什么我要向你走来,不用担心我试图研究它但没有成功。
这是我的清单
[{"id":"28",
"name":"Whitechapel Station",
"logo":"gfx\/whitechapel_station\/whitechapel_station_logo.gif",
"x":"85129",
"y":"36575",
"extentsX1":"0",
"extentsX2":"0",
"extentsY1":"0",
"extentsY2":"0",
"zoomlevel":"4",
"code":"PRJ",
"asset_type":"fixed",
"symbol":"project"}
,{"id":"46",
"name":"Connaught Tunnel",
"logo":"gfx\/connaught_tunnel\/connaught_tunnel_logo.",
"x":"91668",
"y":"35238",
"extentsX1":"0",
"extentsX2":"0",
"extentsY1":"0",
"extentsY2":"0",
"zoomlevel":"4",
"code":"PRJ",
"asset_type":"fixed",
"symbol":"project"}
]
我真正想到的是,只提取每个big {}的“id”和“name”。你有什么想法吗?
干杯队友。
克莱门特
编辑:代码通常不像这样。这只是一条没有回报的大直线,如下所示。
[{"id":"28","name":"Whitechapel Station","logo":"gfx\/whitechapel_station\/whitechapel_station_logo.gif","x":"85129","y":"36575","extentsX1":"0","extentsX2":"0","extentsY1":"0","extentsY2":"0","zoomlevel":"4","code":"PRJ","asset_type":"fixed","symbol":"project"},{"id":"46","name":"Connaught Tunnel","logo":"gfx\/connaught_tunnel\/connaught_tunnel_logo.","x":"91668","y":"35238","extentsX1":"0","extentsX2":"0","extentsY1":"0","extentsY2":"0","zoomlevel":"4","code":"PRJ","asset_type":"fixed","symbol":"project"}]
答案 0 :(得分:4)
您发布的示例采用JSON格式。为了反序列化JSOn字符串,您应该使用JSON.NET等工具。
首先,创建一个与要反序列化的属性匹配的c#对象:
public class MyObject
{
public int id { get; set; }
public string name { get; set; }
}
然后,反序列化:
var myObjects = JsonConvert.DeserializeObject<List<MyObject>>(theString);
然后,您可以使用这些值:
int id = myObjects[0].id;
string name = myObjects[0].name;
答案 1 :(得分:0)
好的,基本上我做了一个很大的错误。 我在每个[或]和{或}之间添加了字符。 解决了!