[
["Sender", "service@mydomain.com"],
["Date", "Sat, 19 Dec 201520:41:31 +0000"],
["X-Mailgun-Sid", "WyI0ZjRjNyIsICJyYWplZXZrbXh4eddHh4eDMzMzMzQHlhaG9vLmNvbSIsICJjNGExZiJd"],
["Received", "by luna.mailgun.net with HTTP; Sat, 19 Dec 2015 20:41:31+0000"],
["Message-Id", "<201512192024131.73374.12565@mydomain.com>"],
["Reply-To", "junky01@hotmail.com"],
["X-Mailgun-Skip-Verification", "false"],
["To", "John Myers <testxxxxxx33333@yahoo.com>"], ["From", "\"Inc.\" <service@mydomain.com>"],
["Subject", "Test subject"],
["Mime-Version", "1.0"],
["Content-Type",
["multipart/mixed", { "boundary": "e43d638b70f04a40889d14f4c8422953" } ]
]
]
When using JObject (VB.net), JObject.parse throws this error:
Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 2, position 2.---- at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader) at Newtonsoft.Json.Linq.JObject.Parse(String json)
But when I copy the above string into online Json viewers, they all seem to be parsing it fine.
Your JSON does not represent an object; it is an array (of arrays). Therefore, you cannot use JObject.Parse()
. Instead, use JArray.Parse()
, which can handle arrays, or use JToken.Parse()
, which can handle either arrays or objects.
string json = @"
[
[""Sender"", ""service@mydomain.com""],
[""Date"", ""Sat, 19 Dec 201520:41:31 +0000""],
[""X-Mailgun-Sid"", ""WyI0ZjRjNyIsICJyYWplZXZrbXh4eddHh4eDMzMzMzQHlhaG9vLmNvbSIsICJjNGExZiJd""],
[""Received"", ""by luna.mailgun.net with HTTP; Sat, 19 Dec 2015 20:41:31+0000""],
[""Message-Id"", ""<201512192024131.73374.12565@mydomain.com>""],
[""Reply-To"", ""junky01@hotmail.com""],
[""X-Mailgun-Skip-Verification"", ""false""],
[""To"", ""John Myers <testxxxxxx33333@yahoo.com>""],
[""From"", ""\""Inc.\"" <service@mydomain.com>""],
[""Subject"", ""Test subject""],
[""Mime-Version"", ""1.0""],
[""Content-Type"",
[""multipart/mixed"", { ""boundary"": ""e43d638b70f04a40889d14f4c8422953"" } ]
]
]";
JArray rows = JArray.Parse(json);
foreach (JArray row in rows)
{
Console.WriteLine(string.Join(": ", row.Select(r => r.ToString())));
}
Fiddle: https://dotnetfiddle.net/VRs47S
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.