我有一个简单的PHP脚本,在后端使用json_encode方法输出字符串数组。它输出如下:如何正确地拆分字符串数组使用C#
["8090123","8090456","8090789","8090321","8090654"]
现在,我想解析它在我的C#代码,但我似乎无法正确解析它。
下面是我的C#代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
using (WebClient wc = new WebClient())
{
string myString = wc.DownloadString("https://magforex.biz/list.php");
string[] words = myString.Split(',');
for (var i = 0; i < words.Length; i++)
{
// i just hardcoded the index for now
Console.WriteLine(words[0]);
break;
}
Console.ReadLine();
}
}
}
}
代码运行得很好,但它输出以下结果["8090123"
这不是我想要的东西。
对不起,我刚刚开始与C#和有限的知识。
我想要的只是字符串8090123
,以便我可以稍后进行比较。
感谢您提前帮忙。
使用JSON库像[JSON.NET(https://www.nuget.org/packages/Newtonsoft.Json/) –
使用JSON库,你不想手动解析它。 – giannisf