简体   繁体   English

如何从字符串中获取参数并将其存储在变量中? (C#)

[英]How can I get parameters out of a string and store them in variables? (C#)

So I have a single string downloaded that will have this format: 因此,我下载了一个具有以下格式的字符串:

  "MatchId": "83570b03-2963-4b44-834c-bf77c74f2d0a",
  "MatchType": 3,
  "GameMode": 3,
  "SeasonId": null,
  "PlaylistId": "282fc197-7bf1-4865-81ec-a312d07567b6",
  "Teams": {
    "1": {
      "TeamSize": 2
    },
    "2": {
      "TeamSize": 2
    }
  },
  "MapId": "skirmish\\design\\MP_Veteran\\MP_Veteran",
  "MatchStartDate": {
    "ISO8601Date": "2017-02-24T21:20:42.024Z"
  },
  "PlayerMatchDuration": "PT35M39.4550853S",
  "PlayerIndex": 3,
  "TeamId": 1,
  "TeamPlayerIndex": 1,
  "LeaderId": 3,
  "PlayerCompletedMatch": true,
  "PlayerMatchOutcome": 2,
  "XPProgress": {
    "PreviousTotalXP": 23300,
    "GameplayXP": 600,
    "ChallengesXP": 0,
    "UpdatedTotalXP": 23900,
    "CompletedSpartanRanks": []

What I want to know is if I have a separate class with variables such as 'MatchId', 'MatchType', 'GameMode' etc. How can I input this string and automatically store all of the values into the correct variable? 我想知道的是,如果我有一个带有变量的单独类,例如'MatchId','MatchType','GameMode'等。如何输入此字符串并将所有值自动存储到正确的变量中?
Thanks :) 谢谢 :)

This looks like JSON, does this have a surrounding { and } ? 看起来像JSON,它周围有{}吗? If so you need to parse it as JSON which should be pretty easy if you use something like what Icepickle suggested (NewtonSoft.JSON) 如果是这样,则需要将其解析为JSON,如果您使用类似Icepickle建议的内容(NewtonSoft.JSON),这应该非常容易

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从C#的列表中获取第一个字符串? - How can I get the first string out of a list in C#? 如何获取字符串的特定部分并将其分配给c#中的变量? - How to get specific parts of string and assign them to variables in c#? 是否可以使用运行时变量设置Func &lt;&gt;函数,以忽略将它们作为C#中的参数传递? - Can I set a Func<> function with runtime variables to omit passing them as parameters in C#? 我怎样才能解构C#7中超出参数的值元组? - How can I Deconstruct Value Tuples that are out parameters in C# 7? 如何在字符串列表的两个索引中获取值并将它们分配给两个字符串变量C# - How to get values in two indexes of a string list and assign them to two string variables C# 如何获取 DataGridView 中两个特定单元格的值并将它们存储在变量中 - How can I get the value of two specific cells in the DataGridView and store them in variables 如何在 C# 中获取传递的参数名称(使用 nameof) - How can I get a passed parameters name in C# (with nameof) 如何从 C# 中的字符串中提取一个数字 - How can I pick out a number from a string in C# 如何将我的变量从dropdownlist asp.net转移到total并在c#中打印出来? - How can I get my variables to carry from dropdownlist asp.net to total and print out in c#? 如何使用C#HttpRequest获取ASP应用程序变量? - How can I get ASP Application variables with C# HttpRequest?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM