亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將Json字符串轉換為C#對象列表

將Json字符串轉換為C#對象列表

我想將json字符串轉換為對象列表。請幫我。如果由來完成,那會更有幫助NewtonJson。我試過了,但是沒有用。我不想要該json的所有值。MatrixModel中提到的這是一個對象public class MatrixModel{     public string S1 { get; set; }     public string S2 { get; set; }     public string S3 { get; set; }     public string S4 { get; set; }     public string S5 { get; set; }     public string S6 { get; set; }     public string S7 { get; set; }     public string S8 { get; set; }     public string S9 { get; set; }     public string S10 { get; set; }     public int ScoreIfNoMatch { get; set; }}這是Json String    "[       {         "Question": {           "QuestionId": 49,           "QuestionText": "Whats your name?",           "TypeId": 1,           "TypeName": "MCQ",           "Model": {             "options": [               {                 "text": "Rahul",                 "selectedMarks": "0"               },               {                 "text": "Pratik",                 "selectedMarks": "9"               },               {                 "text": "Rohit",                 "selectedMarks": "0"               }             ],             "maxOptions": 10,             "minOptions": 0,             "isAnswerRequired": true,             "selectedOption": "1",             "answerText": "",             "isRangeType": false,             "from": "",             "to": "",             "mins": "02",             "secs": "04"           }         },         "CheckType": "",         "S1": "",         "S2": "",         "S3": "",         "S4": "",         "S5": "",         "S6": "",         "S7": "",         "S8": "",         "S9": "Pratik",         "S10": "",         "ScoreIfNoMatch": "2"       },
查看完整描述

3 回答

?
白衣染霜花

TA貢獻1796條經驗 獲得超10個贊

public static class Helper{
    public static string AsJsonList<T>(List<T> tt)
    {
        return new JavaScriptSerializer().Serialize(tt);
    }
    public static string AsJson<T>(T t)
    {
        return new JavaScriptSerializer().Serialize(t);
    }
    public static List<T> AsObjectList<T>(string tt)
    {
        return new JavaScriptSerializer().Deserialize<List<T>>(tt);
    }
    public static T AsObject<T>(string t)
    {
        return new JavaScriptSerializer().Deserialize<T>(t);
    }}


查看完整回答
反對 回復 2019-09-26
  • 3 回答
  • 0 關注
  • 761 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號