如何使用ASP.NET c#从服务器获取JSON格式的数据

本文关键字:JSON 获取 格式 数据 服务器 何使用 ASP NET | 更新日期: 2023-09-27 18:29:40

如何使用ASP.NET c#从服务器获取JSON格式的数据?

我知道如何使用php获取JSON格式的数据,但我也在尝试使用c#。

如何使用ASP.NET c#从服务器获取JSON格式的数据

当您从服务器端发布JSON时,请考虑以下内容:

  1. 数据:JSON.stringfy(人),

  2. contentType:"application/json"

在您的客户端:

  1. 从HttpCurrent.Context.request.InputStream.获取请求正文

  2. 读取输入流并转换为字符串

  3. 反序列化json对象

这样做::

string json;
using(var reader = new StreamReader(Request.InputStream)){
        json = reader.ReadToEnd();
    }
var person = Json.Decode(json);

教程:http://www.mikesdotnetting.com/article/220/posting-data-with-jquery-ajax-in-asp-net-razor-web-pages

如何:使用WebRequest类请求数据