0
[
  ["Sender", "[email protected]"], 
  ["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", "<[email protected]>"], 
  ["Reply-To", "[email protected]"], 
  ["X-Mailgun-Skip-Verification", "false"], 
  ["To", "John Myers <[email protected]>"], ["From", "\"Inc.\" <[email protected]>"], 
  ["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.

1 Answer 1

2

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"", ""[email protected]""], 
  [""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"", ""<[email protected]>""], 
  [""Reply-To"", ""[email protected]""], 
  [""X-Mailgun-Skip-Verification"", ""false""], 
  [""To"", ""John Myers <[email protected]>""], 
  [""From"", ""\""Inc.\"" <[email protected]>""], 
  [""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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.