如何解析每天都在变化的Json Property? [英] How to parse a Json Property that changes everyday?

查看:120
本文介绍了如何解析每天都在变化的Json Property?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我必须解析一个在线JSON文本,我能够解析普通的JSON,但是在这一个中,我需要解析每天更改的属性的属性名称,因为它是在当天之后命名的。

Hi, I am currently developing an app where I have to parse an online JSON text, I am able to parse normal JSON, however in this one, the Property name of the property I need to parse changes every day, as it is named after the day.

以下是一个示例:

"recreationareas":{"Basketball Court":{"6/10/2014":"7:00AM - 9:00PM","6/11/2014":"7:00AM - 9:00PM","6/12/2014":"7:00AM - 9:00PM","6/13/2014":"7:00AM - 7:00PM","6/14/2014":"CLOSED","6/15/2014":"CLOSED"

正如您在篮球场看到的那样,其内部的属性以今天,明天等日期命名。

As you can see for the Basketball Court there are properties inside it named after the date of today, tomorrow, and so on.

这是我在RootObject cs文件中的内容

This is what I have in my RootObject cs file

public class BasketballCourt

{

     [JsonProperty(PropertyName =" 6/9/2014")]
$
    public string __invalid_name__Today {get;组; }
     [JsonProperty(PropertyName =" 6/10 / 2014")]
$
    public string __invalid_name__Tomorrow {get;组; }
     [JsonProperty(PropertyName =" 6/11/2014")]
$
    public string __invalid_name__TwoDays {get;组; }
     [JsonProperty(PropertyName =" 6/12/2014")]
$
    public string __invalid_name__ThreeDays {get;组; }
}

public class BasketballCourt
{
     [JsonProperty(PropertyName = "6/9/2014")]
    public string __invalid_name__Today { get; set; }
     [JsonProperty(PropertyName = "6/10/2014")]
    public string __invalid_name__Tomorrow { get; set; }
     [JsonProperty(PropertyName = "6/11/2014 ")]
    public string __invalid_name__TwoDays { get; set; }
     [JsonProperty(PropertyName = "6/12/2014 ")]
    public string __invalid_name__ThreeDays { get; set; }
}

公共类娱乐区

{

    [JsonProperty(PropertyName =" Basketball Court")]
$
    public FitnessCenter __invalid_name__BasketballCourt {get;组; }
}

public class Recreationareas
{
    [JsonProperty(PropertyName = "Basketball Court")]
    public FitnessCenter __invalid_name__BasketballCourt { get; set; }
}

在那里你可以看到我访问这些属性的唯一方法是硬编码属性名字,这是不可能看到我每天都要改变它,并且每天更新应用程序。

And there you can see that the only way for me to access these properties is to hard code the property name, which would be impossible seeing that I would have to change it every day, and update the app every day.

所以,我想知道是否有人曾经遇到过这个或知道如何解析这种类型的JSON。

So, I was wondering if anyone has ever encountered this before or knows how to parse this type of JSON.

谢谢!

Thank you!

推荐答案

嗨Sin,

http://blogs.msdn.com/b/wsdevsol/archive/2014/01/09/consuming-rest -services-in-your-windows-store-and-phone-applications.aspx

你可以只返回一个var,它将动态创建对象(无需定义要反序列化的类。)

You can just return a var and it will create the object dynamically (without having to define a class to de-serialize to).


这篇关于如何解析每天都在变化的Json Property?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆