Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在C语言中将Json数组转换为字符串数组#_C#_Json_List - Fatal编程技术网

C# 如何在C语言中将Json数组转换为字符串数组#

C# 如何在C语言中将Json数组转换为字符串数组#,c#,json,list,C#,Json,List,我有一个Json输出,如下所示 [ { "eng_trans": "wide, outstretched," }, { "eng_trans": "width,breadth, town, street,earth, country, greatness." }, { "eng_trans": "wife, the mistress of the house," }, { "e

我有一个Json输出,如下所示

[
    {
        "eng_trans": "wide, outstretched,"
    },
    {
        "eng_trans": "width,breadth, town, street,earth, country, greatness."
    },
    {
        "eng_trans": "wife, the mistress of the house,"
    },
    {
        "eng_trans": "wide agricultural tract,"
    },
    {
        "eng_trans": "waste land the land which is not suitabie for cultivation."
    }] 
我只需要带out键的单词,并且需要在c#中形成一个字符串列表。有没有更好的办法

public class RootObject
{
     public string eng_trans { get; set; }
}
这就行了

  //list to store the words
 List<string> wordList = new List<string>();
 //Convert your json to string.I have already done it for you.
 string json = "[{      \"eng_trans\": \"wide, outstretched,\"  },  {       \"eng_trans\": \"width,breadth, town, street,earth, country, greatness.\"   },  {       \"eng_trans\": \"wife, the mistress of the house,\" },  {       \"eng_trans\": \"wide agricultural tract,\" },  {       \"eng_trans\": \"waste land the land which is not suitabie for cultivation.\"   }]";
 //Add Newtonsoft.Json from Nuget to do this deserialization.
 List<RootObject> eng_trans_List = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RootObject>>(json);

  foreach(RootObject obj in eng_trans_List)
  {
      string[] str =  obj.eng_trans.Split(',');
      foreach(string word in str)
      {
         wordList.Add(word);
      }
  }
//存储单词的列表
List wordList=新列表();
//将json转换为字符串。我已经为您完成了。
string json=“[{\'eng\'u trans\”:“宽,伸展,\”,{\'eng\'trans\”:“宽,宽,镇,街,地球,国家,伟大。\”,{\'eng\'trans\”:“妻子,房子的主人,\”,{\'eng\'trans\”:“宽农业区,\”,{'eng\'trans\”:“荒地:不适合耕种的土地;
//从Nuget添加Newtonsoft.Json以执行此反序列化。
List eng_trans_List=Newtonsoft.Json.JsonConvert.DeserializeObject(Json);
foreach(eng_trans_列表中的RootObject obj)
{
字符串[]str=obj.eng_trans.Split(',');
foreach(str中的字符串字)
{
添加(word);
}
}

使用Newtonsoft.json.dll

并将Json字符串转换为数组

检查以下链接:

到目前为止,您尝试了哪些,哪些不适合您。例如,您是否尝试使用模型类?或者在不使用模型类的情况下使用它,但只使用LINQ来JSON-将其解析为
JArray
,然后从数组中的每个
JObject
中获取
eng_trans
值。您有newtonsoft JSON吗?请提供更多信息。仅链接的答案不被视为好答案。