1

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 thninking is becase I have something like a Jaosn Array but I am not alet ot get it when I am tryint to cast from JObject to JArray

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,\"}]"
}
Devsined
  • 3,363
  • 6
  • 30
  • 48

1 Answers1

0

Hi I found the solution to this issue and I want to share with you.

The problem was how i was building the JSON with a wrong JSON format. As a result the parse using JObject and Jtoken didn't work. But with a JSON well formatted the parse works using a standard examples uisng JObject and JToken

this post show detail on how create the right JSON which is being sending tot the Web API Issue with JSON.stringify adding a extra \ and “” to my Json object Issue with JSON.stringify adding a extra \ and "" to my Json object

A Json well formatted will be like this:

    {
    "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,"}]
    }

Issue with JSON.stringify adding a extra \ and "" to my Json object

Community
  • 1
  • 1
Devsined
  • 3,363
  • 6
  • 30
  • 48