Newtonsoft Jobject Parse Array

So, how do handle this case with our Json.NET JObject instance. As a demonstration, let’s say the requirement is to just take the first one if it’s an array. Here’s a little program to demonstrate. Overall, the Json.NET looks like the solution we were looking for, with a concise few lines of code to parse and process the result. Please advise, how I can loop the Json JObject array in Newtonsoft.Json, or if you know other JSon package for F# can do the same job, please share your code. Thanks, Sunday, April 15, 2018 10:05 PM. How to Parse JSON Array using Newtonsoft. How to Parse JSON Array using Newtonsoft. I have tried but didn't get how to parse it. Parsing JSON Array using JArray.Parse This sample parses a JSON array using JArray Parse(String). Here are the examples of the csharp api class Newtonsoft.Json.Linq.JArray.Parse(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

Parse using JObject with JSON on the WEB API

Dec 14, 2012 02:53 PM|sinedyip|LINK

Hi I am sending using Jquery in a post a JObject to my Web API but I am having issues using the Newtonsoft.Json library to parse it.

I am getting the data in the WEB API but i am not able to Parse using the online example.

the is at the end of this post. I need some help parsing that object. Any idea?

My controller look like this:

// POST api/returnvalues/5
public string Post(int id, JObject value)
{
var temp = value;

....

}

and my Jquery to send the information is like this.

function PostAPIRequest(address) {

var jObject = JSON.stringify(FilterValuesArray);
var responseJson = null;
$.ajax({
url: address,
type: 'POST',
dataType: 'json',
data: { JObject: jObject },
success: function (data) {
responseJson = data
ProcessDataResponse(responseJson);
//TODO: REFRESH THE DATA GRID
},
error: function (xhr, ajaxOptions, thrownError) {
//TODO redirect to the error page and send error email there.
alert(xhr.status);
alert(thrownError);
}
})
}

JSON

{
'JObject': '[{'key':'20','value':'us'},{'key':'30','value':'mini'},{'key':'31','value':'audi'},{'key':'21','value':'4,5,13,14,15,'},{'key':'29','value':'8,'},{'key':'32','value':'7,'}]'
}

Active1 year, 2 months ago
$begingroup$

I'm looking for the best solution.

Here is a response from server and i need to get Organizations list:

Here is my convert method:

Code works, but I'm looking for a better Convert Method. Can I do without converting to JArray?

t3chb0tNewtonsoft Jobject Parse Array

Newtonsoft Jobject Parse Array List

38.2k7 gold badges61 silver badges142 bronze badges
Nikita GoncharukNikita Goncharuk

Newtonsoft Jobject Parse

$endgroup$

2 Answers

$begingroup$

Given that you are already using the ToObject, consider simplifying the code for readability and the advantage of not having to convert anything.

The actual response appears to be of no concern so using a dynamic simplifies things. Converting back to strongly typed objects by calling ToObject<T> was a good choice and should work out fine.

NkosiNkosi
Array$endgroup$$begingroup$

Json.Net will (by default) accept missing fields without a problem when doing typed deserialization, so I believe you can do:

ErrorsatzErrorsatz
$endgroup$

Not the answer you're looking for? Browse other questions tagged c#json or ask your own question.