Post JSON Dictionary

POST json dictionary

Due to the way JsonValueProviderFactory is implemented binding dictionaries is not supported.

POST Dictionary as JSON

Dim dict As New Dictionary(Of String, String)
dict.Add("Drinks", "2")
dict.Add("ID", "1")
Dim parameters As String = JsonConvert.SerializeObject(dict, Formatting.None)
Dim Uri As New Uri(String.Format("http://localhost:60627/home/test/"))
Dim webClient As New WebClient()
Dim resByte As Byte()
Dim resString As String
Dim reqString() As Byte
webClient.Headers("content-type") = "application/json"
Dim senddata As Object = JsonConvert.SerializeObject(New With {Key .param = parameters}).ToString()
reqString = Encoding.Default.GetBytes(senddata)
resByte = webClient.UploadData(Uri, "post", reqString)
resString = Encoding.Default.GetString(resByte)

First change this type of Concatination
"{""Pram"":""" + parameters + """}"
for It's Make Little confustion.

And The Data Not Sending To the Server Property Because problem is Escapse Sequence That Concat is Not Given Proper Serialization of the Data.

In Above I Change the Code For

Dim parameters As String = JsonConvert.SerializeObject(dict, Formatting.None)

It's Change the Data

{"Drinks":"2","ID":"1"}

The Next Serialization It's Change the

{"param":"{\"Drinks\":\"2\",\"ID\":\"1\"}"}

But Your Serlization of Send Data is

{"param":"{"Drinks":"2","ID":"1"}"}

So, the Data is Not Sending Properly
Sample Image

I was Checked Properly it's Working Fine....

Post Json Dictionary to the controller

Instead of receiving the Class object, you should receive it as string and then serialize into object like below.

public JsonResult Tflow(string basedetails)
{
//some code
var model = new JavascriptSerializer().Deserialize<JsonFileContentInputs>(basedetails);
// Your code
}

How can I deserialize JSON to a simple Dictionarystring,string in ASP.NET?

Json.NET does this...

string json = @"{""key1"":""value1"",""key2"":""value2""}";

var values = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);

More examples: Serializing Collections with Json.NET

WebAPI - Posting to dictionary with json

The default JsonFormatter is unable to bind Dictionary from Javascript Array because it doesn't define a key to each item.

You need to use an Object instead:

"HandleBars": {
"something": "value"
}

How to send a json dictionary as a field in a Multipart Form API Requests call?

You should convert python dict to JSON string representation using json.dumps(payload_data) instead of concatenating "{" and "}" since the latter might be error-prone.



Related Topics



Leave a reply



Submit