Answer the question
In order to leave comments, you need to log in
How to use the Newtonsoft.Json directive?
using System;
using Newtonsoft.Json;
namespace Example
{
public class Program
{
public static void Main(string[] args)
{
dynamic json = JsonConvert.DeserializeObject(e.Data); // данные получаются от WS соединения
//Пример данных в json - data: "{"name":"Phone","id":"2532","last_id":"88883"}"
Console.WriteLine(json.data); // Тут отдает - "name":"Phone","id":"2532","last_id":"88883"
Console.WriteLine(json.data.name); // тут выдает ошибку Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ""Newtonsoft.Json.Linq.JValue" не содержит определения для "name""
}
}
}
Answer the question
In order to leave comments, you need to log in
//Пример данных в json - data: "{"name":"Phone","id":"2532","last_id":"88883"}"
data
you have a string
in the field . do the deserialization again, but for this line dynamic
of describing the data model as a class, then perhaps Json.NET can be forced to do this automatically (using attributes on the field data
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question