小编use*_*041的帖子

从C#中的JSON读取特定值

所以我有一个JSON字符串,我只想读取一个特定的值.我如何Read me please!从下面的字符串中选择" "?

var readString = /*Read me please!*/
Run Code Online (Sandbox Code Playgroud)

JSON字符串:

"{\"aString\":\"Read me please!\"}"
Run Code Online (Sandbox Code Playgroud)

为了更好地理解,我如何在这里做同样的事情?(只是" Read me please!"):

"{\"Result\":
    {    
    \"aString\":\"Read me please!\",
    \"anotherString\":\"Dont read me!\"
    }    
}"
Run Code Online (Sandbox Code Playgroud)

如果两种方案都有不同的解决方案,我想知道两者.

PS:我不希望将值保存到object/class左右.只是暂时在里面var readString.

.net c# json json-deserialization

4
推荐指数
1
解决办法
3214
查看次数

C#:在Tuple中使用Task <>

如果我删除Tuple并使用Task<bool>或,这将有效Task<string>.

 public async Tuple<Task<bool>, string> Test()
        {

            //....

            return new Tuple<Task<bool>, string>(false, "a string");
        }
Run Code Online (Sandbox Code Playgroud)

知道如何使这项工作?

c# async-await

1
推荐指数
1
解决办法
1176
查看次数

JSON解析问题

我正在将JSON数据存储到课堂中.但是,我很难解决JSON下面的第二行,BadGuy.我无法正确存储数据.

{
     \"First\":{\"FirstBool\":1, \"aString\":\"hello\"},
     \"BadGuy\":\"BadGuy says hello\" //<--- this one, how do I tackle this in code below?
}
Run Code Online (Sandbox Code Playgroud)
public class First
{
    [JsonProperty("FirstBool")]
    public int FirstBool { get; set; }

    [JsonProperty("aString")]
    public string aString { get; set; }
}     

public class BadGuy //my poorly attempt
{
    [JsonProperty("BadGuy")]
    public string BadGuy { get; set; }
}


public class ClsResult
{
    [JsonProperty("First")]
    public First First { get; set; }    

   [JsonProperty("BadGuy")] // another poorly attempt
    public …
Run Code Online (Sandbox Code Playgroud)

c# json

0
推荐指数
1
解决办法
52
查看次数

标签 统计

c# ×3

json ×2

.net ×1

async-await ×1

json-deserialization ×1