如何从C#webmethod中的POST请求中获取json数组 [英] How to get json array from POST request in C# webmethod
本文介绍了如何从C#webmethod中的POST请求中获取json数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C#中开发了Webmethod。这里服务器以下面的格式发送POST请求中的Json数组。
I have developed Webmethod in C#. Here server send the Json Array in POST Request in the Below format.
[{ "name" : "AAAA", "address" : "Chennai"},{"name": "BBBB", "address":"Trichy"}]
如何读取这个Json并序列化这个Json?
我尝试过:
当我将请求更改为以下类型时,我的代码正常工作。
How to read this Json and Serialize this Json?
What I have tried:
When I Change the Request to below type my code is working Properly.
"JsonData":{[{ "name" : "AAAA", "address" : "Chennai"},{"name": "BBBB", "address":"Trichy"}]}
但我的请求不是这样的。
But my request was not like this.
推荐答案
您的数据格式不正确,必须用大括号括起来{
和}
。请参阅 JSON简介 [ ^ ]。
Your data is not in a correct format, it must be enclosed in curly braces{
and}
. See JSON Introduction[^].
尝试
try
string json = "[{ \"name\" : \"AAAA\", \"address\" : \"Chennai\"},{\"name\": \"BBBB\", \"address\":\"Trichy\"}]";
json = "JsonData:{" + json + "}";
这篇关于如何从C#webmethod中的POST请求中获取json数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文