M
M
MrMastire2022-03-27 18:02:17
JSON
MrMastire, 2022-03-27 18:02:17

How to get content from variable in json C#?

I use (Newtonsoft.Json)

I have a Delo class which describes Json File

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestArea
{
    public class Delo
    {
        public string Name { get; set; }
        public string Podpis { get; set; }
        public int Number { get; set; }
    }
}


and json file

{"Name":"vasya","Podpis":"rar","Number":0}

When button is clicked, I want to display the contents of NAME, how can I implement this?
(I tried this, but I don't know why it doesn't work)
string temp1 = File.ReadAllText("info.json");
            JsonConvert.DeserializeObject<Delo>(temp1);
            // просто в обращении к temp1. (name не существует), а в классе он есть.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2022-03-27
@MrMastire

var text = File.ReadAllText("info.json");
var delo = JsonConvert.DeserializeObject<Delo>(text);
Console.WriteLine(delo.Name);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question