• c# 匿名反序列化


    1.先new一个匿名对象,然后再反序列化好处是能点点点,坏处是得先new匿名对象

    2.借用Newtonsoft.Json.Linq.JObject.Parse,好处是不需要new匿名对象,坏处是不能点点点

    var strModel='{
    	"UserId": "30260696",
    	"OutLinkUrl": "tt",
    	"blogContent": "tt",
    	"Status": "1",
    	"Content": {
    		"text": "tt",
    		"medias": [{
    			"original": "http://ysjzpublic001.oss-cn-beijing.aliyuncs.com/circle/965eb72c92a549dd/6FhRuQ/4ef66281-2aab-4a05-8a73-73094817acdd.jpg",
    			"type": 1,
    			"thumbnail": "",
    			"imgwidth": "",
    			"imgheight": ""
    		}, {
    			"original": "http://ysjzpublic001.oss-cn-beijing.aliyuncs.com/circle/965eb72c92a549dd/6FhRuQ/8cf0ee1c-cba4-452a-a84e-dd9a3054df94.png",
    			"type": 1,
    			"thumbnail": "",
    			"imgwidth": "",
    			"imgheight": ""
    		}]
    	}
    }';
    
    1.c#反序列化
    var blogRequest = Newtonsoft.Json.Linq.JObject.Parse(strModel);
    var Content=blogRequest["Content"];
    var text=blogRequest["Content"]["text"].ToString();
    var text=blogRequest["Content"]["medias"][0]["original"].ToString();
    
    2.js toJsonObject
    var blogRequest=JSON.Parse(strModel);
    

      

  • 相关阅读:
    10.26 饮食
    10.25 饮食
    10.24饮食
    关于 wpf 的ICommand 的 CanExecute CanExecuteChanged func action的认识
    2018 10 23
    [Java]先有Class还是先有Object?
    [Java]如何制作一个WordCount-Plus的Plugin
    [java] 软工实践WordCount-Plus
    [java]基本数据类型
    [java]第一个程序
  • 原文地址:https://www.cnblogs.com/liuqiyun/p/9525896.html
Copyright © 2020-2023  润新知