如何将字符串分割成多维数组

本文关键字:数组 分割 字符串 | 更新日期: 2023-09-27 18:08:25

我已经开始在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"}
]

我所想到的实际上是提取每一束大{}的"id"answers"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"}]

如何将字符串分割成多维数组

您发布的示例是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;

好的,基本上我做了一个厚错误。我在每个[or]和{or}之间添加了字符"。解决了!