我有一個API調用,它看起來像的結果:自定義JSON,轉換爲對象
{"Operations":[{"OperationId":"2","OperationObjectId":"Application","OperationName":"UnlockSession","OperationParameters":[{"Name":"viewModel","Value":"model"},{"Name":"returnUrl","Value":"https://"}],"OperationCaller":{"UserPrincipalName":"bob","ClientIPAddress":""},"OperationResult":"Succeeded","OperationStatus":200,"OperationRequest":{"Method":"POST","Url":""},"OperationStartedTime":"2013-08-20T12:04:17.5462357Z","OperationCompletedTime":"2013-08-20T12:04:17.9979469Z"}],"ContinuationToken":null}
理想我想將它轉換爲對象,所以我可以做的東西,如:
object.OperationObjectID; // gives Application
object.Method; // gives POST
object.OperationResult; // gives Succeeded
有人知道這是怎麼完成的嗎? JSON解析是否需要知道格式?
感謝, 安德魯
什麼是 「自定義」 JSON是什麼意思? –
請看看這個StackOverflow的答案: [http://stackoverflow.com/questions/2246694/how-to-convert-json-object-to-custom-c-sharp-object][1] [1]:http://stackoverflow.com/questions/2246694/how-to-convert-json-object-to-custom-c-sharp-object – RRR
使用[json.net](http://james.newtonking的.com /項目/ JSON-net.aspx) –