Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# foreach object in array json

// Answer By: Cam3r0n#0481
// Pro Tip : Use this to convert your JSON to C# Classes
// https://json2csharp.com/

// The example json
// {"chat":[{"author":"Bob","content":"My name is Bob and I approve this message.","timestamp":1604438166}],"error":false,"message":"Chat fetched."}

public class ChatMessage
{
    public string author;
    public string content;
    public int timestamp;
}

public class ChatResponse
{
    public List<ChatMessage> chat;
    public bool error;
    public string message;
}

ChatResponse response = JsonConvert.DeserializeObject<ChatResponse>(json);
foreach (var message in response.chat)
{
    rtbChat.AppendText($"{message.author}: {message.content}
");
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# load form 
Csharp :: c# get certain character from string 
Csharp :: toggle unity c# 
Csharp :: how to make a character run in unity 
Csharp :: c# array.join 
Csharp :: find how many digits a number has 
Csharp :: get tag unity 
Csharp :: unity check if camera can see object 
Csharp :: how to deserialize string array in c# 
Csharp :: exceldatareader example c# 
Csharp :: c# datetime for filename 
Csharp :: c# datagridview select row right click 
Csharp :: IHttpContextAccessor 
Csharp :: c# today without time 
Csharp :: how to validate if date is a weekday or weekend c# 
Csharp :: c# join strings with comma 
Csharp :: priority queue c# 
Csharp :: Edit file C# 
Csharp :: check if value in list c# 
Csharp :: export list to excel c# 
Csharp :: What is the yield keyword used for in C#? 
Csharp :: meaning of ??= in c# 
Csharp :: set margin programmatically wpf c# 
Csharp :: unity time scale 
Csharp :: c# timer 30 seconds 
Csharp :: C# Read() and ReadKey() 
Csharp :: LINQ: 2 join with group by 
Csharp :: serial number unity pro 
Csharp :: c# sum object values 
Csharp :: wpf keyboard press event 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =