简体   繁体   English

反序列化数组中的 400 个 json 对象

[英]Deserializing 400 json objects in an array

I am deserializing json objects in an array.我正在反序列化数组中的 json 对象。 I've successfully done this and it automatically brings up 200 users back.我已经成功地做到了这一点,它会自动带回 200 个用户。 I want to bring back 400 users instead of 200 but can't find a way to do this.我想带回 400 个用户而不是 200 个用户,但找不到方法来做到这一点。 This is the code I have:这是我的代码:

var json = Get("https: ... users"); //there's a link in here
List<User> List;
List = JsonConvert.DeserializeObject<List<User>>(json.Content);

JsonConvert.DeserializeObject 上没有任何内容限制结果...如果某些对象的 JSON 不正确,您是否同意?

One way may be to parse the incoming json string and cap it at the number you want.一种方法可能是解析传入的 json 字符串并将其限制在您想要的数字上。 For example if you know each object begins or ends with something, you can proceed through the string, count how many instances of the object you encounter, then when you reach your limit, delete the rest of the objects (that is remove their representations from the string).例如,如果您知道每个对象以某事物开头或结尾,您可以继续遍历字符串,计算遇到的对象实例的数量,然后当您达到限制时,删除其余对象(即从字符串)。 Then, when you have finished, deserialize the string.然后,完成后,反序列化字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM