相关疑难解决方法(0)

将JSON反序列化为C#动态对象?

有没有办法将JSON内容反序列化为C#4动态类型?为了使用DataContractJsonSerializer,跳过创建一堆类会很不错.

.net c# serialization json dynamic

919
推荐指数
22
解决办法
67万
查看次数

在.Net 4.0中找不到JavaScriptSerializer

我似乎无法在Visual Studio 2010中找到JavaScriptSerializer对象和System.Web.Script.Serialization命名空间.我需要将某些内容序列化为JSON我应该使用什么?

是的,我已经System.Web.Extensions在项目中包含了(在System.Web.Extensions.dll中).这让我感到震惊的原因是什么?

  • 我知道在3.5中System.Web.Extensions被标记为过时

c# jsonserializer visual-studio

292
推荐指数
11
解决办法
29万
查看次数

将Json String转换为C#Object List

我想将json字符串转换为Object列表.请帮我.如果完成它会更有帮助NewtonJson.

我试过了,但它不起作用.我不想要那个json的所有值.就是在MatrixModel中提到的

这是一个对象

public class MatrixModel
{
    public string S1 { get; set; }
    public string S2 { get; set; }
    public string S3 { get; set; }
    public string S4 { get; set; }
    public string S5 { get; set; }
    public string S6 { get; set; }
    public string S7 { get; set; }
    public string S8 { get; set; }
    public string S9 { get; set; }
    public string S10 { get; set; }
    public …
Run Code Online (Sandbox Code Playgroud)

javascript c# asp.net-mvc json json.net

30
推荐指数
2
解决办法
14万
查看次数

将此LINQ表达式转换为Lambda

大家好,我很难将下面的linq表达式(左连接实现)转换为lambda表达式(用于学习).

var result = from g in grocery
       join f in fruit on g.fruitId equals f.fruitId into tempFruit
       join v in veggie on g.vegid equals v.vegid into tempVegg
       from joinedFruit in tempFruit.DefaultIfEmpty()
       from joinedVegg in tempVegg.DefaultIfEmpty()
       select new { g.fruitId, g.vegid, fname = ((joinedFruit == null) ? string.Empty :     joinedFruit.fname), vname = ((joinedVegg == null) ? string.Empty : joinedVegg.vname) };
Run Code Online (Sandbox Code Playgroud)

有人可以建议我如何做到这一点.

如果有人给我"C#Lambdas&Linqs"的优秀教程链接,我真的很感激

c# linq lambda

14
推荐指数
4
解决办法
3万
查看次数

如何将此JSON结果解析为对象?

我需要将此JSON字符串解析为我的"WeatherJson"类型的对象.但是我不知道如何解析字符串中的阵列,如"'天气’: [{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}].实体类会是什么样子?

JSON字符串:

{
  "coord": {"lon":79.85,"lat":6.93},
  "sys": {
    "type": 1, 
    "id": 7864, 
    "message": 0.0145,
    "country": "LK",
    "sunrise": 1435883361,
    "sunset": 1435928421
  },
  "weather": [
     {"id":802, "main":"Clouds", "description":"scattered clouds", "icon":"03d"}
  ],
  "base": "stations",
  "main": {
    "temp": 302.15,
    "pressure": 1013,
    "humidity": 79,
    "temp_min": 302.15,
    "temp_max": 302.15
  },
  "visibility":10000,
  "wind": { "speed": 4.1, "deg": 220 },
  "clouds": { "all": 40 },
  "dt": 1435893000,
  "id":1248991,
  "name":"Colombo",
  "cod":200
}
Run Code Online (Sandbox Code Playgroud)

编辑

我需要从代码中检索以下值:

WeatherJson w = new WeatherJson();
Console.WriteLine(w.weather.description);
//that above line was retrieved and stored …
Run Code Online (Sandbox Code Playgroud)

.net c# json json.net

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