Click here to Skip to main content
15,897,371 members

I have a json string that I am trying to put into a class so I can loop through the class and proccss the data

Member 8087552 asked:

Open original thread
This should be a simple issue.
I have a data class, and json data, but I cant find a way to change the strong into a json object.
All help would be appreciated.
Here is the string
[{"CampaignID":"F1","Customer":"cust1","Language":"E","Content":[
	{
"Type":"Email",
"Campaign":"t1",
"Card_type":"xxxxx",
"Last4":"xxxx",
"Name":"Rick",
"EmailAddress":"xxxxx@hotmail.com"
}
]},{"CampaignID":"F1","Customer":"cust1","Language":"E","Content":[
	{
"Type":"Email",
"Campaign":"t1",
"Card_type":"xxxxxxxx",
"Last4":"xxxx",
"Name":"Donna",
"EmailAddress":"xxxxx@hotmail.com"
}
]},{"CampaignID":"t1","Customer":"f1","Language":"E","Content":[
	{
"Type":"Email",
"Campaign":"t1",
"Card_type":"xxxxxx",
"Last4":"xxxx",
"Name":"Chelsea Bun",
"EmailAddress":"xxxxxxxxx-poo@hotmail.com"
}
]}]


And here are the classes

public class clsEmail
{

    public string CompanyName { get; set; } = "";
    public string Campaign { get; set; } = "";
    public string CampaignID { get; set; } = "";
    public string Customer { get; set; } = "";

    public string Language { get; set; } = "";
    public IList<Content> Content { get; set; }

}
public class Content
{
    public string Type { get; set; }
    public string Campaign { get; set; }
    public string Card_type { get; set; }
    public string Last4 { get; set; }
    public string Name { get; set; }
    public string EmailAddress { get; set; }
}


What I have tried:

I have tried to convert to json object, loop through an list as well as an array
Tags: C#, JSON, Serialization

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900