我有一个带有多维数组的Newtonsoft JSON jObject变量。
价值如下。我想将此jObject转换为Array,以便我们可以非常轻松地在c#中管理数组。任何人都做得更苗条请帮助我。
{
"DRIVER_CODE": "hk",
"DRV_NAME": "hk",
"DRV_ADDR": "hk",
"DRV_DOB_DT": "07-01-2013",
"DRV_NATIONALITY": "7",
"DRV_PHONE1": "kh",
"DRV_PHONE2": "hk",
"DRV_MOBILE1": "hk",
"DRV_MOBILE2": "hk",
"DRV_LIC_NO": "hk",
"DRV_LIC_ENDORSE": "hk",
"DRV_LIC_ISSUE_DT": "08-01-2013",
"DRV_LIC_EXPIRY_DT": "15-01-2013",
"DRV_LIC_ISSUEDAT": "hk",
"DRV_USER_CODE": "hk",
"DRV_USER_PIN": "hk",
"DRV_STATUS": 1,
"DRV_RELIGION": "1",
"DRV_WEEKLYOFF": "0",
"DRV_PASSPORT_NUMBER": "hk",
"DRV_ISSUED_AT": "kh",
"DRV_ISSUED_DATE": "10-01-2013",
"DRV_EXPIRY_DATE": "18-01-2013",
"DRV_VISA_SPONSOR": "kh",
"DRV_VISA_NUMBER": "hk",
"DRV_VISA_ISSUEDATE": "17-01-2013",
"DRV_VISA_EXPIRYDATE": "15-01-2013",
"DRV_LANG1_CODE": "ARB",
"DRV_LANG2_CODE": "CHN",
"DRV_LANG3_CODE": "ENG",
"NONAVAILABILITY": [
{},
{
"id": 1,
"fromdate": "15-01-2013",
"todate": "15-01-2013",
"reasonVal": "Compassionate Leave",
"ReasonID": "4"
},
{
"id": 2,
"fromdate": "30-01-2013",
"todate": "23-01-2013",
"reasonVal": "Haj Leave",
"ReasonID": "3"
},
{
"id": 3,
"fromdate": "30-01-2013",
"todate": "23-01-2013",
"reasonVal": "Haj Leave",
"ReasonID": "3"
},
{
"id": 4,
"fromdate": "30-01-2013",
"todate": "23-01-2013",
"reasonVal": "Haj Leave",
"ReasonID": "3"
},
{
"id": 5,
"fromdate": "30-01-2013",
"todate": "23-01-2013",
"reasonVal": "Haj Leave",
"ReasonID": "3"
}
]
}
{
"DRIVER_CODE": "hk",
"DRV_NAME": "hk",
"DRV_ADDR": "hk",
"DRV_DOB_DT": "07-01-2013",
"DRV_NATIONALITY": "7",
"DRV_PHONE1": "kh",
"DRV_PHONE2": "hk",
"DRV_MOBILE1": "hk",
"DRV_MOBILE2": "hk",
"DRV_LIC_NO": "hk",
"DRV_LIC_ENDORSE": "hk",
"DRV_LIC_ISSUE_DT": "08-01-2013",
"DRV_LIC_EXPIRY_DT": "15-01-2013",
"DRV_LIC_ISSUEDAT": "hk",
"DRV_USER_CODE": "hk",
"DRV_USER_PIN": "hk",
"DRV_STATUS": 1,
"DRV_RELIGION": "1",
"DRV_WEEKLYOFF": "0",
"DRV_PASSPORT_NUMBER": "hk",
"DRV_ISSUED_AT": "kh",
"DRV_ISSUED_DATE": "10-01-2013",
"DRV_EXPIRY_DATE": "18-01-2013",
"DRV_VISA_SPONSOR": "kh",
"DRV_VISA_NUMBER": "hk",
"DRV_VISA_ISSUEDATE": "17-01-2013",
"DRV_VISA_EXPIRYDATE": "15-01-2013",
"DRV_LANG1_CODE": "ARB",
"DRV_LANG2_CODE": "CHN",
"DRV_LANG3_CODE": "ENG",
"NONAVAILABILITY": [
{},
{
"id": 1,
"fromdate": "15-01-2013",
"todate": "15-01-2013",
"reasonVal": "Compassionate Leave",
"ReasonID": "4"
},
{
"id": 2,
"fromdate": "30-01-2013",
"todate": "23-01-2013",
"reasonVal": "Haj Leave",
"ReasonID": "3"
},
{
"id": 3,
"fromdate": "30-01-2013",
"todate": "23-01-2013",
"reasonVal": "Haj Leave",
"ReasonID": "3"
},
{
"id": 4,
"fromdate": "30-01-2013",
"todate": "23-01-2013",
"reasonVal": "Haj Leave",
"ReasonID": "3"
},
{
"id": 5,
"fromdate": "30-01-2013",
"todate": "23-01-2013",
"reasonVal": "Haj Leave",
"ReasonID": "3"
}
]
}
我试图将NONAVAILABILITY对象转换为数组,但它不成功。任何人已转换此请提交将继电器有帮助。
答案 0 :(得分:0)
JArray nonavailability_array = (JArray)role["NONAVAILABILITY"];
for (Int32 i = 1; i < nonavailability_array.Count; i++)
{
JObject aItem = (JObject)nonavailability_array[i];
datetime dt = Convert.ToDateTime(aItem["fromdate"].ToString().Replace('"', ' ').Trim());
}