Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My code parses a JSON string into a JArray with 3 arrays. One is <string> machineName, the next is a List<string> emails, and the last is a List<string> phoneNumbers. However, when I parse the information and convert the JToken to a string using this:
JArray json = JArray.Parse(input);
var machineName = json[0];
var emailAddresses = json[1].ToString(0);
var phoneNumbers = json[2].ToString(0);


Both my emailAddresses and phoneNumbers look like,
"[\"example@gmail.com\"]"
in the debugger/watches
while I want them to look like
"example@gmail.com"


Ideally, this is what I want the "emailAddresses" string to look like:
example1@gmail.com, example2@gmail.com, example3@gmail.com, example4@gmail.com


What I have tried:

I've tried
var emails = JsonConvert.DeserializeObject(emailAddresses);
var phones= JsonConvert.DeserializeObject(phoneNumbers);


And it formats it correctly, however they are still objects and I need them to be a list of correctly formatted strings.
Posted
Updated 29-Sep-20 10:33am
v2

Resolved this issue by using classes instead. I created a class called PostMessage that contained a string (machineName), List<string> (emails), and List<string> (phone numbers). Then, initialized this class first in my Console App and then sent over the class to the WebAPI for it to pull from.
 
Share this answer
 
Resolved this issue by using classes instead. I created a class called PostMessage that contained a string (machineName), List<string> (emails), and List<string> (phone numbers). Then, initialized this class first in my Console App and then sent over the class to the WebAPI for it to pull from.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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