开发者

Need help using a "root"-less JSON object with Json.Net and JArrays

I'm using the ExportAPI from MailChimp. It sends back a "root"-less Json string like so:

["Email Address", "First Name", "Last Name"]
["jeff@mydomain.com", "Jeff", "Johnson"]
["tubbs@mydomain.com", "Tubbs", "McGraw"]

No brackets, nothing- just a couple of arrays.开发者_运维问答 Loading it into a JArray only picks up the first object:

JArray jsonArray = new JArray.Parse(jsonResponse);
Console.WriteLine(jsonArray);

//Outputs:
//Email Address
//First Name
//Last Name

I'm hoping to copy the contents of the string into a database and need to access the response with LINQ. Any suggestions as to the correct way to work with a Json Object like I've shown above (using Json.net or otherwise?)


Pad the string with a root element, just add '[' and ']'?


This behavior is actually completely on purpose as mentioned in the docs. The reasoning is that a full dump of a list's data can easily be way too large to consistently fit it in memory and parse it. As such, and given the return format, you're expected to use a newline as the delimiter (or read it off the wire that way), parse each object individually, and then do whatever you need with them.

I am not familiar with doing that in C#/Linq, but the PHP example on the docs page does exactly that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜