2017-07-12 7 views
0

私は、次のしているJSONタイプには、現在のJSONオブジェクトをデシリアライズすることはできません(例:{ "名": "値"} ')System.Collections.Generic.List`1'

{ 
"d" : [ 
{ 
"__metadata": { 
"uri": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(95)", "etag": "W/\"2\"", "type": "Microsoft.SharePoint.DataService.ddeerItem", "edit_media": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(95)/$value", "media_src": "http://tools/sites/xxxen/HSE_registreringer/ddeer/ESV Indfasning af ddeer/ESV_MONO A-625 Anion Exchange Resin.docx", "content_type": "application/octetstream", "media_etag": "\"{A5D87498-016D-4FB2-A674-53CC6BB15B6F},3\"" 
}, "Title": "ESV_MONO A-625", "Id": 95, "Path": "/sites/xxxen/HSE_registreringer/ddeer/ESV Indfasning af ddeer" 
}, { 
"__metadata": { 
"uri": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(96)", "etag": "W/\"5\"", "type": "Microsoft.SharePoint.DataService.ddeerItem", "edit_media": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(96)/$value", "media_src": "http://tools/sites/xxxen/HSE_registreringer/ddeer/ESV Indfasning af ddeer/ESV_Indfasning af AMBERJET 1500 H.docx", "content_type": "application/octetstream", "media_etag": "\"{DC1B3362-C845-40B3-97F3-A76BF2C2298F},9\"" 
}, "Title": "Indfasning af 1500 H", "Id": 96, "Path": "/sites/xxxen/HSE_registreringer/ddeer/ESV Indfasning af ddeer" 
}, { 
"__metadata": { 
"uri": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(104)", "etag": "W/\"5\"", "type": "Microsoft.SharePoint.DataService.ddeerItem", "edit_media": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(104)/$value", "media_src": "http://tools/sites/xxxen/HSE_registreringer/ddeer/SSV-indfasning af Castrol Radicool.docx", "content_type": "application/octetstream", "media_etag": "\"{A0F7213E-8F53-4023-8BE0-B721A4238D32},5\"" 
}, "Title": "indfasning radicool", "Id": 104, "Path": "/sites/xxxen/HSE_registreringer/ddeer" 
}, { 
"__metadata": { 
"uri": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(105)", "etag": "W/\"2\"", "type": "Microsoft.SharePoint.DataService.ddeerItem", "edit_media": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(105)/$value", "media_src": "http://tools/sites/xxxen/HSE_registreringer/ddeer/AVV_Udfasning af Araldit.docx", "content_type": "application/octetstream", "media_etag": "\"{7BB35C40-5AA8-4D8D-A1B1-D76E210B54B1},2\"" 
}, "Title": "Araldit ARC ", "Id": 105, "Path": "/sites/xxxen/HSE_registreringer/ddeer" 
}, { 
"__metadata": { 
"uri": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(106)", "etag": "W/\"2\"", "type": "Microsoft.SharePoint.DataService.ddeerItem", "edit_media": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(106)/$value", "media_src": "http://tools/sites/xxxen/HSE_registreringer/ddeer/AVV_Udfasning af Casco Strong Rapid.docx", "content_type": "application/octetstream", "media_etag": "\"{45DB0319-F298-4776-B69F-7F3260C2318A},2\"" 
}, "Title": "AVV af Casco Strong Epoxy", "Id": 106, "Path": "/sites/xxxen/HSE_registreringer/ddeer" 
}, { 
"__metadata": { 
"uri": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(107)", "etag": "W/\"2\"", "type": "Microsoft.SharePoint.DataService.ddeerItem", "edit_media": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(107)/$value", "media_src": "http://tools/sites/xxxen/HSE_registreringer/ddeer/HCV_Udfasning af Belzona 1211.docx", "content_type": "application/octetstream", "media_etag": "\"{BC4F04EE-3D48-44FF-B4D8-909023177E0D},2\"" 
}, "Title": "HCV af Belzona 1211", "Id": 107, "Path": "/sites/xxxen/HSE_registreringer/ddeer" 
}, { 
"__metadata": { 
"uri": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(108)", "etag": "W/\"3\"", "type": "Microsoft.SharePoint.DataService.ddeerItem", "edit_media": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(108)/$value", "media_src": "http://tools/sites/xxxen/HSE_registreringer/ddeer/AVV_Udfasning af Araldit 02.docx", "content_type": "application/octetstream", "media_etag": "\"{127F69BC-131A-4C92-8436-AF3D3EF84C54},3\"" 
}, "Title": "Araldit 858", "Id": 108, "Path": "/sites/xxxen/HSE_registreringer/ddeer" 
}, { 
"__metadata": { 
"uri": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(109)", "etag": "W/\"6\"", "type": "Microsoft.SharePoint.DataService.ddeerItem", "edit_media": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(109)/$value", "media_src": "http://tools/sites/xxxen/HSE_registreringer/ddeer/AVV_Indfasning af KEMA TL-676 Trykluft.docx", "content_type": "application/octetstream", "media_etag": "\"{14F342E7-D7F1-45E0-AF25-CFCBC0845A13},6\"" 
}, "Title": "Trykluft", "Id": 109, "Path": "/sites/xxxen/HSE_registreringer/ddeer" 
}, { 
"__metadata": { 
"uri": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(110)", "etag": "W/\"2\"", "type": "Microsoft.SharePoint.DataService.ddeerItem", "edit_media": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(110)/$value", "media_src": "http://tools/sites/xxxen/HSE_registreringer/ddeer/AVV_Udfasning af ITW trykluft.docx", "content_type": "application/octetstream", "media_etag": "\"{893A9D28-EB70-4F1C-BF87-3AE145AF1B15},2\"" 
}, "Title": "Trykluft", "Id": 110, "Path": "/sites/xxxen/HSE_registreringer/ddeer" 
}, { 
"__metadata": { 
"uri": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(111)", "etag": "W/\"1\"", "type": "Microsoft.SharePoint.DataService.ddeerItem", "edit_media": "http://tools/sites/xxxen/HSE_registreringer/_vti_bin/listdata.svc/ddeer(111)/$value", "media_src": "http://tools/sites/xxxen/HSE_registreringer/ddeer/Marloherm.docx", "content_type": "application/octetstream", "media_etag": "\"{2BA74EE4-1F57-48B5-8BE5-CCB27C0B0E02},1\"" 
}, "Title": "Marloherm", "Id": 111, "Path": "/sites/xxxen/HSE_registreringer/ddeer" 
} 
] 
} 

私は

を次のように私のモデルクラスは、「次の構文

SPDocument list = JsonConvert.DeserializeObject<SPDocument>(response.Content); 

を使用して、それをデシリアライズしかし、上記のエラーを得ることに保つために

をしよう

public class SPResult 
{ 
    public string Name { get; set; } 
    public string Title { get; set; } 
    public string Path { get; set; } 
    public List<Metadata> __metadata { get; set; } 
} 

public class SPObject 
{ 
    public List<SPResult> results { get; set; } 
} 

public class SPDocument 
{ 
    public List<SPObject> d { get; set; } 
} 
public class Metadata 
{ 
    public string uri { get; set; } 
    public string etag { get; set; } 
    public string type { get; set; } 

} 

同じ問題で他の多くの質問を見上げたが、これを処理する方法を理解することはできません。あなたはJSONのためのクラスを生成することができますjson2csharp.com

エラーは、サイト上のパスに 'D'

答えて

1

です。あなたのケースで はこれができ:あなたのコード内ので

public class Metadata 
{ 
    public string uri { get; set; } 
    public string etag { get; set; } 
    public string type { get; set; } 
    public string edit_media { get; set; } 
    public string media_src { get; set; } 
    public string content_type { get; set; } 
    public string media_etag { get; set; } 
} 

public class D 
{ 
    public Metadata __metadata { get; set; } 
    public string Title { get; set; } 
    public int Id { get; set; } 
    public string Path { get; set; } 
} 

public class RootObject 
{ 
    public List<D> d { get; set; } 
} 

SPObjectはunnecesaryです。

SPDocument

は次のようになります。

public class SPDocument 
{ 
    public List<SPResult> d { get; set; } 
} 
1

あなたSPObject含まれていませんSPResult JSONデータに基づいて。

お客様SPObjectは、お客様のSPResultです。

これを削除すると完了です。

あなたSPDocumentは次のようになります。

public class SPDocument 
{ 
    public List<SPResult> d { get; set; } 
} 
関連する問題