猿问

将 json 响应转换为 C# 变量

如何在控制台应用程序中将返回的 JSON 值转换为变量?我从 rest api 调用中得到多个公司(750+)的 JSON 响应并将其写入控制台应用程序,如下所示:


"companies": [

    {

        "guid": "81eb95d6-d89e-4e93-aad0-eff89a450fcf",

        "name": "Example Company 1",

        "rating": 770,

        "rating_date": "2018-05-27"

          },

    {

        "guid": "81eb95d6-d89e-4e93-aad0-eff89a450fcf",

        "name": "Example Company 2",

        "rating": 810,

        "rating_date": "2018-05-27"

    },

    {

        "guid": "81eb95d6-d89e-4e93-aad0-eff89a450fcf",

        "name": "Example Company 3",          

        "rating": 760,

        "rating_date": "2018-05-27"

    },`

使用 SharePoint 客户端,然后我希望将这些公司值作为共享点列表中的项目上传。


    {

        ClientContext context = new  ClientContext("http://exampleSharepoint/List");


        List companiesList = context.Web.Lists.GetByTitle("Companies");


        ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();

        ListItem newItem = companiesList.AddItem(itemCreateInfo);

        newItem["Title"] = CompanyTitle;

        newItem["guid"] = Guid;

        newItem["Rating"] = Rating;

        newItem["Rating Date"] = RatingDate;

        newItem.Update();


        context.ExecuteQuery();


    }

我看过 json deserializer,但很难将它应用到我的上下文中。任何帮助深表感谢。


慕少森
浏览 161回答 1
1回答
随时随地看视频慕课网APP
我要回答