Как я могу десериализовать эту строку?C#

Место общения программистов C#
Ответить
Anonymous
 Как я могу десериализовать эту строку?

Сообщение Anonymous »

Я пытаюсь десериализовать эту строку, чтобы поместить данные в таблицу (я использую Blazor), мне нужны только ItemIds ItemSections (на самом деле мне нужно поместить их все в таблицу), остальная часть от него можно избавиться. Дело в том, что я пытаюсь заставить это работать, но немного застрял.
Это строка:
{
"id": 6,
"description": "Accounting",
"position": 0,
"enabled": true,
"itemSections": [
{
"itemId": 7,
"sectionId": 6,
"item": {
"id": 7,
"type": 2,
"description": "ctb_1",
"notes": "",
"shortDescription": "ctb_1",
"code": "",
"enabled": true,
"guid": null,
"itemSections": [
null
],
"layouts": [],
"scopes": [],
"users": [],
"bookmarks": [],
"tenantId": null
},
"section": null,
"position": 0
},
{
"itemId": 8,
"sectionId": 6,
"item": {
"id": 8,
"type": 2,
"description": "ctb_2",
"notes": "",
"shortDescription": "ctb_2",
"code": "string",
"enabled": true,
"guid": null,
"itemSections": [
null
],
"layouts": [],
"scopes": [],
"users": [],
"bookmarks": [],
"tenantId": null
},
"section": null,
"position": 0
},
{
"itemId": 9,
"sectionId": 6,
"item": {
"id": 9,
"type": 2,
"description": "TIMELINE ADEMPIMENTI",
"notes": "s",
"shortDescription": "TIMELINE ADEMPIMENTI",
"code": "string",
"enabled": true,
"guid": null,
"itemSections": [
null
],
"layouts": [],
"scopes": [],
"users": [],
"bookmarks": [],
"tenantId": null
},
"section": null,
"position": 0
}
],
"users": [
{
"id": 1,
"name": "Administrator",
"email": null,
"role": 1,
"login": "string",
"password": "string",
"enabled": true,
"canImpersonate": true,
"theme": null,
"layouts": [],
"userFilters": [],
"items": [],
"scopes": [],
"sections": [
null
],
"bookmarks": [],
"tenantId": null
}
]
}

Это десериализация, на всякий случай (элементы — это список):
items = JsonSerializer.Deserialize(jsonDocument.RootElement, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
});

А также таблица, которую я пытаюсь поместить, в которую я пытаюсь поместить все данные, возможно, здесь тоже что-то не так:



@* headers *@
Id
Description
Position
Enabled
Item Sections
Users
Data



@foreach (var item in items)
{
@* dati *@

@item.Id
@item.Description
@item.Position
@item.Enabled
@string.Join(", ", item.ItemSections)
@string.Join(", ", item.Users)



Подробнее здесь: https://stackoverflow.com/questions/785 ... his-string
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»