需要引用:System.Web.Extensions

/// <summary>
/// json的信息。保证定义的变量和json的字段一样(也可以使用struct)
/// </summary>
public class JsonInfo
{
public string res_code { get; set; }
public string res_info { get; set; }
public List<Persion> persionList;
} public class Persion
{
public string name { get; set; }
public string age { get; set; }
} public class OperateJson
{
public static void ParseJson()
{
string json = "{'res_code':'0','res_info':'ok','persionList':[{'name':'ladygaga','age':'50'},{'name':'swift','age':'42'}]}";
JavaScriptSerializer js = new JavaScriptSerializer();
JsonInfo jsonInfo = js.Deserialize<JsonInfo>(json);
} public static string CreateJson(object objectList)
{
JavaScriptSerializer js = new JavaScriptSerializer();
string json = js.Serialize(objectList);
return json;
}
}

使用

 private void button3_Click(object sender, EventArgs e)
{
OperateJson.ParseJson();
} private void button4_Click(object sender, EventArgs e)
{
JsonInfo jsonInfo = new JsonInfo();
jsonInfo.res_code = "0";
jsonInfo.res_info = "ok";
jsonInfo.persionList = new List<Persion>(); Persion persion = new Persion();
persion.name = "lady gaga";
persion.age = "50";
jsonInfo.persionList.Add(persion); Persion persion1 = new Persion();
persion1.name = "swift";
persion1.age = "42";
jsonInfo.persionList.Add(persion1); OperateJson.CreateJson(jsonInfo);
}

  

c#操作json 使用JavaScriptSerializer的更多相关文章

  1. C#中用JavaScriptSerializer和Json.Net操作json格式的文件

    1.json文件 2.写出对应的类 //折扣 public class Discount { public string Qty { get; set; } public string percent ...

  2. C#操作JSON

    http://www.cnblogs.com/LiZhiW/p/3624729.html C#操作JSON 1. .NET对JSON的支持介绍............................. ...

  3. .NET操作JSON

    http://www.cnblogs.com/txw1958/archive/2012/08/01/csharp-json.html JSON文件读入到内存中就是字符串,.NET操作JSON就是生成与 ...

  4. C#操作Json(转)

    原文:http://wenku.baidu.com/link?url=3dlqKdF26ZdQIAcX9jvP2ZYEtl3J0sKOV8XuHQI0Rz4SjB9S46nqmGiMXUVQa_1Pm ...

  5. C#操作JSON学习

    JSON(全称为JavaScript Object Notation) 是一种轻量级的数据交换格式.它是基于JavaScript语法标准的一个子集. JSON采用完全独立于语言的文本格式,可以很容易在 ...

  6. c#操作json的两种方式

    总结一下C#操作json的两种方式,都是将对象和json格式相转. 1.JavaScriptSerializer,继承自System.Web.Script.Serialization private ...

  7. C#操作json类型数据

    将对象序列化为 JavaScript 对象表示法 (JSON),并将 JSON 数据反序列化为对象. 此类不能继承. // msdn 例子: namespace SL_DataContractJson ...

  8. 让C#可以像Javascript一样操作Json

    Json的简介 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的文本格式,但是也使用了 ...

  9. JavaScript操作JSON的方法总结,JSON字符串转换为JSON对象

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式.同时,JSON是 JavaScript 原生格式,这意 ...

随机推荐

  1. Python函数-input()

    input([prompt]) 如果[prompt]是存在的,它被写入标准输出中没有换行.然后函数读取输入,将其转换为一个字符串,然后返回. >>> s = input('--> ...

  2. h5 离线缓存小demo

    传统的web应用是在线应用,这其实也是web的特色,对于PC时代问题并不大,但到了移动互联网时代,设备终端位置不再固定,依赖无线信号,网络的可靠性变得更低.比如:在火车上,穿山越岭进隧道,便无法访问w ...

  3. 12.Selenium+Python案例 -- 今日头条(获取科技栏目的所有新闻标题)

    一:具体代码实现 # -*- coding: utf-8 -*-# @Time : 2018/7/26 16:33# @Author : Nancy# @Email : NancyWangDL@163 ...

  4. python爬虫彩票案例,并自动发微信

    import requests from bs4 import BeautifulSoup import itchat import time,datetime all = [{1, 2, 3, 7, ...

  5. 由于簇计数比预计的高,格式化操作无法完成——Allocation Unit Size Adjustments for Larger NTFS Volumes.

    Allocation Unit Size Adjustments for Larger NTFS Volumes.   Problem: When trying to format a new vol ...

  6. AngularJS:依赖注入

    ylbtech-AngularJS:依赖注入 1.返回顶部 1. AngularJS 依赖注入 什么是依赖注入 wiki 上的解释是:依赖注入(Dependency Injection,简称DI)是一 ...

  7. 批量删除osd的shell脚本

    cluster环境: # cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) # ceph -v ceph version 12. ...

  8. 文件锁简单操作(lockfileEx\unlockfileEx)

    #include "stdafx.h"#include <Windows.h>#include <iostream> using namespace std ...

  9. leetcode628

    这道题十分不容易啊,做到半夜. class Solution { public: static int cmp628(int a, int b) { return a > b; } static ...

  10. xcode 编译报错“Cannot create __weak reference in file using manual reference counting”解决办法<转>

    http://blog.csdn.net/ouq68/article/details/51003876 解决方法: Please set ‘Weak References in Manual Reta ...