私は、次のRootObjectオブジェクトを用意する必要があります。オブジェクトのリストからオブジェクトを作成する
public class Document2
{
public string homecommunityid { get; set; }
public string repositoryid { get; set; }
public string documentuuid { get; set; }
public string doctype { get; set; }
}
public class Document
{
public Document2 document { get; set; }
}
public class RootObject
{
public List<Document> documents { get; set; }
}
次のDocumentQueryオブジェクトのリストからRootObjectオブジェクトを取り込む必要があります。
public class DocumentQuery
{
public string doctype { get; set; }
public string homecommunityid { get; set; }
public string repositoryid { get; set; }
public string documentuuid { get; set; }
}
私は次のように何かをしようとしています:
RootObject doc = new RootObject()
{
Document= obj.Select(s => new Document()
{
document = new Document2()
{
doctype = s.doctype
}
})
};
私はこの形式でできJSONになるこの必要があります。
{
"documents": [
{
"document": {
"homecommunityid": "",
"repositoryid": "",
"documentuuid": "",
"doctype": ""
}
}
]
}
これまでに試したコードを共有してください...コミュニティがあなたにリファクタリングして助けます.. –
どうして2つのクラス( 'Document2'と' DocumentQuery')が本質的に同じですか?なぜあなたは何も役に立たないように見える介入型( 'Document')を持っていますか?あなたは 'RootObject'をまだ移植しようとしましたか?それはLINQでかなりシンプルにすべきです。 –
基本に戻る。それは単に新しいクラスの問題です。 – niksofteng