c# – 我如何将json字符串转换为Json对象

参见英文答案 > Convert JSON String to JSON Object c#                                    7个
我有json字符串的方法,我想将json字符串转换为json对象.我试过下面的方法它显示内存超出如何解决错误.
我试过这个字符串抛出ajax它的工作正常.但我如何从后端的字符串转换为数据表.任何建议.
我的代码.

      public ActionResult JosnString()
        {

      string str = "{\"delivery\": [{\"status\": 2, \"resp_msg\": \"5.4.1 [renard.allenll@transdev.com]: Recipient address rejected: Access denied [HE1EUR02FT054.eop-EUR02.prod.protection.outlook.com]\", \"mail_from\": \"vision@transdev.com\", \"time_started\": 1539808420, \"time_finished\": 1539808426, \"resp_code_description\": \"The requested command failed because the user's mailbox was unavailable (for example because it was not found, or because the command was rejected for policy reasons).\", \"sender_id\": 9007074, \"campaign_id\": \"\", \"rcpt_to\": \"renard.allenll@transdev.com\", \"tries\": 0, \"resp_code\": 550, \"tracking_id\": \"2939c3ea-59e8-4019-9f4b-4cd4214254b4\", \"resp_class\": 10, \"subject\": \"Las Vegas Notification - Passenger Fall- No Injury (Auto Email \u2013 Do Not Repl (#718701)\"}, {\"status\": 2, \"resp_msg\": \"5.4.1 [Theodrick.mccullom@transdev.com]: Recipient address rejected: Access denied [HE1EUR02FT042.eop-EUR02.prod.protection.outlook.com]\", \"mail_from\": \"vision@transdev.com\", \"time_started\": 1539809940, \"time_finished\": 1539809944, \"resp_code_description\": \"The requested command failed because the user's mailbox was unavailable (for example because it was not found, or because the command was rejected for policy reasons).\", \"sender_id\": 9007074, \"campaign_id\": \"\", \"rcpt_to\": \"theodrick.mccullom@transdev.com\", \"tries\": 0, \"resp_code\": 550, \"tracking_id\": \"2c75c0e1-cf9c-4c92-9d11-e6cebfc28300\", \"resp_class\": 10, \"subject\": \"Las Vegas Notification - Safety- Passenger Event (Auto Email \u2013 Do Not Reply) (#724957)\"}, {\"status\": 2, \"resp_msg\": \"5.4.1 [tricia.mumford@transdev.com]: Recipient address rejected: Access denied [VE1EUR02FT003.eop-EUR02.prod.protection.outlook.com]\", \"mail_from\": \"vision@transdev.com\", \"time_started\": 1539810919, \"time_finished\": 1539810926, \"resp_code_description\": \"The requested command failed because the user's mailbox was unavailable (for example because it was not found, or because the command was rejected for policy reasons).\", \"sender_id\": 9007074, \"campaign_id\": \"\", \"rcpt_to\": \"tricia.mumford@transdev.com\", \"tries\": 0, \"resp_code\": 550, \"tracking_id\": \"2f7a87e4-513e-4358-b1b6-bb8febdff35d\", \"resp_class\": 10, \"subject\": \"SV Alert Alert (#725159)\"}, {\"status\": 2, \"resp_msg\": \"5.4.1 [Theodrick.mccullom@transdev.com]: Recipient address rejected: Access denied [HE1EUR02FT033.eop-EUR02.prod.protection.outlook.com]\", \"mail_from\": \"vision@transdev.com\", \"time_started\": 1539815408, \"time_finished\": 1539815412, \"resp_code_description\": \"The requested command failed because the user's mailbox was unavailable (for example because it was not found, or because the command was rejected for policy reasons).\", \"sender_id\": 9007074, \"campaign_id\": \"\", \"rcpt_to\": \"theodrick.mccullom@transdev.com\", \"tries\": 0, \"resp_code\": 550, \"tracking_id\": \"e9bb47c0-22d5-4781-ac2a-9bef56232255\", \"resp_class\": 10, \"subject\": \"Las Vegas Notification - Safety- Accident with no injuries (Auto Email \u2013 Do (#733279)\"}, {\"status\": 2, \"resp_msg\": \"5.4.1 [francisco.sanchez@transdev.com]: Recipient address rejected: Access denied [HE1EUR02FT026.eop-EUR02.prod.protection.outlook.com]\", \"mail_from\": \"vision@transdev.com\", \"time_started\": 1539815465, \"time_finished\": 1539815469, \"resp_code_description\": \"The requested command failed because the user's mailbox was unavailable (for example because it was not found, or because the command was rejected for policy reasons).\", \"sender_id\": 9007074, \"campaign_id\": \"\", \"rcpt_to\": \"francisco.sanchez@transdev.com\", \"tries\": 0, \"resp_code\": 550, \"tracking_id\": \"c5baf56c-89da-4388-a692-da2b84862f0a\", \"resp_class\": 10, \"subject\": \"Malfunctioning GPS, please reboot this these device(s). (#733299)\"}, {\"status\": 2, \"resp_msg\": \"5.4.1 [carl.parr@transdev.com]: Recipient address rejected: Access denied [HE1EUR02FT019.eop-EUR02.prod.protection.outlook.com]\", \"mail_from\": \"vision@transdev.com\", \"time_started\": 1539816062, \"time_finished\": 1539816067, \"resp_code_description\": \"The requested command failed because the user's mailbox was unavailable (for example because it was not found, or because the command was rejected for policy reasons).\", \"sender_id\": 9007074, \"campaign_id\": \"\", \"rcpt_to\": \"carl.parr@transdev.com\", \"tries\": 0, \"resp_code\": 550, \"tracking_id\": \"e6299d04-5aac-43d3-8593-1a3c548e336f\", \"resp_class\": 10, \"subject\": \"SV Alert Alert (#733431)\"}, {\"status\": 2, \"resp_msg\": \"5.4.1 [Theodrick.mccullom@transdev.com]: Recipient address rejected: Access denied [HE1EUR02FT038.eop-EUR02.prod.protection.outlook.com]\", \"mail_from\": \"vision@transdev.com\", \"time_started\": 1539816315, \"time_finished\": 1539816318, \"resp_code_description\": \"The requested command failed because the user's mailbox was unavailable (for example because it was not found, or because the command was rejected for policy reasons).\", \"sender_id\": 9007074, \"campaign_id\": \"\", \"rcpt_to\": \"theodrick.mccullom@transdev.com\", \"tries\": 0, \"resp_code\": 550, \"tracking_id\": \"ea9caff3-364e-4a32-8365-98a897a6bbc5\", \"resp_class\": 10, \"subject\": \"Las Vegas Notification - Safety- Accident with no injuries (Auto Email \u2013 Do (#734371)\"}, {\"status\": 2, \"resp_msg\": \"5.4.1 [francisco.sanchez@transdev.com]: Recipient address rejected: Access denied [VE1EUR02FT035.eop-EUR02.prod.protection.outlook.com]\", \"mail_from\": \"vision@transdev.com\", \"time_started\": 1539820874, \"time_finished\": 1539820877, \"resp_code_description\": \"The requested command failed because the user's mailbox was unavailable (for example because it was not found, or because the command was rejected for policy reasons).\", \"sender_id\": 9007074, \"campaign_id\": \"\", \"rcpt_to\": \"francisco.sanchez@transdev.com\", \"tries\": 0, \"resp_code\": 550, \"tracking_id\": \"b81e47e5-5211-425a-a7be-5b75379bf3b1\", \"resp_class\": 10, \"subject\": \"Malfunctioning GPS, please reboot this these device(s). (#735305)\"}, {\"status\": 2, \"resp_msg\": \"5.4.1 [francisco.sanchez@transdev.com]: Recipient address rejected: Access denied [VE1EUR02FT053.eop-EUR02.prod.protection.outlook.com]\", \"mail_from\": \"vision@transdev.com\", \"time_started\": 1539826279, \"time_finished\": 1539826283, \"resp_code_description\": \"The requested command failed because the user's mailbox was unavailable (for example because it was not found, or because the command was rejected for policy reasons).\", \"sender_id\": 9007074, \"campaign_id\": \"\", \"rcpt_to\": \"francisco.sanchez@transdev.com\", \"tries\": 0, \"resp_code\": 550, \"tracking_id\": \"c2b7a520-a994-49a6-b34b-96113f5960d5\", \"resp_class\": 10, \"subject\": \"Malfunctioning GPS, please reboot this these device(s). (#735539)\"}, {\"status\": 2, \"resp_msg\": \"5.4.1 [Ramona.Trotter@transdev.com]: Recipient address rejected: Access denied [HE1EUR02FT023.eop-EUR02.prod.protection.outlook.com]\", \"mail_from\": \"vision@transdev.com\", \"time_started\": 1539829584, \"time_finished\": 1539829587, \"resp_code_description\": \"The requested command failed because the user's mailbox was unavailable (for example because it was not found, or because the command was rejected for policy reasons).\", \"sender_id\": 9007074, \"campaign_id\": \"\", \"rcpt_to\": \"ramona.trotter@transdev.com\", \"tries\": 0, \"resp_code\": 550, \"tracking_id\": \"264645cd-0792-445b-9fd4-1cccd0746cfb\", \"resp_class\": 10, \"subject\": \"Driver Dispatch Log Entries (Auto Email \u2013 Do Not Reply) (#736221)\"}], \"last_update_time\": 1540421479.703088}";
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                DataSet dt = (DataSet)JsonConvert.DeserializeObject(str, (typeof(DataSet)));
            return new EmptyResult();
}
最佳答案
你可以试试这个

string str = "{ 'context_name': { 'lower_bound': 'value', 'pper_bound': 'value', 'values': [ 'value1', 'valueN' ] } }";
    JavaScriptSerializer j = new JavaScriptSerializer();
    object a = j.Deserialize(str, typeof(object));

转载注明原文:c# – 我如何将json字符串转换为Json对象 - 代码日志