I'm not familiar with the Json
method you are using, but from version 3.1 .Net Core has its own json serializer JsonSerializer
(in System.Text.Json
namespace) and I'm going to use that one in my answer.
As of your issue, you are serializing twice and it might not give you the resultsList
in your final result as an array of string which you might be expecting.
Your first conversion will result in an array of strings -
["alice","bob","charlie"]
But your second conversion, depending on the serializer used, might put the entire array above inside a string and give that as the value of resultsList
in your final result.
You should serialize once, the final object only -
// you need to import the following
// using System.Text.Json;
List<string> userNames = new List<string>();
names.Add("alice");
names.Add("bob");
names.Add("charlie");
return JsonSerializer.Serialize(new { success = true, resultsList = userNames });
It will give you resultsList
as an array of strings -
{"success":true,"resultsList":["alice","bob","charlie"]}
Then you can loop through that array on the client end like -
result.resultsList.forEach(p=> console.log(p))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…