string jtext = "{\"jiangsu\":[{\"wuxi\":\"无锡\"},{\"suzhou\":\"苏州\"},{\"nanjing\":\"南京\"}] }";

//解析Json对象
JObject a = (JObject)JsonConvert.DeserializeObject(jtext);
string a1 = a["jiangsu"][2]["nanjing"].ToString();
//对Json数据进行解析
Console.WriteLine(a1);
Console.ReadLine();

//解析Json数组
string a4 = a["jiangsu"].ToString();
//从Json数据中取一个数组出来
JArray a2 = (JArray)JsonConvert.DeserializeObject(a4);
string a3 = a2[2]["nanjing"].ToString();
//对Json数据进行解
Console.WriteLine(a3);
Console.ReadLine();
---------------------
案例H3BPM主数据同步:

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Services;
using System.Xml;
using Newtonsoft.Json;
using OThinker.H3.BizBus.BizService;
using OThinker.H3;
using OThinker.H3.Data;
using OThinker.H3.WorkSheet;
using System.Collections;
using System.Reflection;
using System.Web.Script.Serialization;
using Newtonsoft.Json.Linq;
using log4net;

namespace OThinker.H3.Portal
{
/// <summary>
/// MaterialMasterDataSynchro 的摘要说明
/// </summary>
/// <summary>
/// BPMFsscWebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]
public class MaterialMasterDataSynchro : IBaseJob
{
public MaterialMasterDataSynchro()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private readonly ILog _logger = LogManager.GetLogger(typeof(JobSyncSapSupplier));

public override void JobMethod(ZD_SyncTaskConfig plan)
{
GetMaterialInfo(plan.SyncSuccessBeginTime.ToString("yyyy.MM.dd"));
}

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
private IEngine _Engine = null;
/// <summary>
/// 流程引擎的接口,该接口会比this.Engine的方式更快,因为其中使用了缓存
/// </summary>
public IEngine Engine
{
get
{
if (OThinker.H3.WorkSheet.AppConfig.ConnectionMode == ConnectionStringParser.ConnectionMode.Mono)
{
return OThinker.H3.WorkSheet.AppUtility.Engine;
}
return _Engine;
}
set
{
_Engine = value;
}
}

public string AdminId
{
get
{
return OThinker.H3.WorkSheet.AppUtility.Engine.Organization.GetUnitByCode("Administrator").ObjectID;
}
}
ReturnResult result;

/// <summary>
/// SAP获得物料主数据信息
/// string Json = "{\"EX_RETURN\":[{\"MATNR\":\"test\"}] }";
/// </summary>
[WebMethod(Description = "获取SAP物料主数据信息")]
public string GetMaterialInfo(string lastSuccessDate)
{

DataTable dataTable = new DataTable(); //实例化
string Json = string.Empty;
try
{
Dictionary<string, object> dic = new Dictionary<string, object>();
//List<Item> list = new List<Item>();
//dic.Add("MT_MM_WLZSJ.IM_INPUT", "");
Json = GetInterfaceDataService.ExecuteBizNonQueryToJson("MaterialMasterDataInterface", "SI_MM_WLZSJ_OS", dic);
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
javaScriptSerializer.MaxJsonLength = Int32.MaxValue; //取得最大数值
JObject jObject = (JObject)JsonConvert.DeserializeObject(Json); //此处放json数据
string ex_return = jObject["EX_RETURN"].ToString();
ArrayList arrayList = javaScriptSerializer.Deserialize<ArrayList>(ex_return);
foreach (Dictionary<string, object> dictionary in arrayList)
{
if (dataTable.Columns.Count == 0)
{
foreach (string current in dictionary.Keys)
{
dataTable.Columns.Add(current, dictionary[current].GetType());
}
}
DataRow dataRow = dataTable.NewRow();
foreach (string current in dictionary.Keys)
{
dataRow[current] = dictionary[current];
}
dataTable.Rows.Add(dataRow); //循环添加行到DataTable中
}
}
catch (Exception ex)
{
result = new ReturnResult(false, "SAP主数据增量同步失败!" + ex);
}
if (dataTable.Rows.Count > 0)
{
StringBuilder sb = new StringBuilder();
string sql = string.Format(@"select * from Tab_SAPMaterialMasterData");
DataTable SelectDt = AppUtility.Engine.Query.QueryTable(sql);
if (SelectDt.Rows.Count > 0)
{
string DeleteSql = string.Format(@"delete from Tab_SAPMaterialMasterData");
DataTable DeleteDt = AppUtility.Engine.Query.QueryTable(DeleteSql);
}
for (int j = 0; j < dataTable.Rows.Count; j++)
{
string InsertSql = string.Format(@"INSERT Tab_SAPMaterialMasterData(MATNR,MAKTX,BWKEY,VPRSV,BKLAS,MTART,MEINS,MATKL,BESKZ)
VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')",
dataTable.Rows[j]["MATNR"].ToString(),
dataTable.Rows[j]["MAKTX"].ToString(),
dataTable.Rows[j]["BWKEY"].ToString(),
dataTable.Rows[j]["VPRSV"].ToString(),
dataTable.Rows[j]["BKLAS"].ToString(),
dataTable.Rows[j]["MTART"].ToString(),
dataTable.Rows[j]["MEINS"].ToString(),
dataTable.Rows[j]["MATKL"].ToString(),
dataTable.Rows[j]["BESKZ"].ToString());
sb.Append(InsertSql);
}
OThinker.H3.WorkSheet.AppUtility.Engine.Query.CommandFactory.CreateCommand().ExecuteNonQuery(sb.ToString());
result = new ReturnResult(true, "SAP主数据增量同步成功!");
}
else
{
result = new ReturnResult(false, "SAP主数据增量同步失败!");
}

return result.ToString();
}
public class Item
{
public string WERKS { get; set; }
}
/// <summary>
/// 将泛型集合类转换成DataTable
/// </summary>
/// <typeparam name="T">集合项类型</typeparam>
/// <param name="list">集合</param>
/// <param name="propertyName">需要返回的列的列名</param>
public static DataTable ToDataTable<T>(IList<T> list, params string[] propertyName)
{
List<string> propertyNameList = new List<string>();
if (propertyName != null)
propertyNameList.AddRange(propertyName);

DataTable result = new DataTable();
if (list.Count > 0)
{
PropertyInfo[] propertys = list[0].GetType().GetProperties();
foreach (PropertyInfo pi in propertys)
{
if (propertyNameList.Count == 0)
{
result.Columns.Add(pi.Name, pi.PropertyType);
}
else
{
if (propertyNameList.Contains(pi.Name))
result.Columns.Add(pi.Name, pi.PropertyType);
}
}

for (int i = 0; i < list.Count; i++)
{
ArrayList tempList = new ArrayList();
foreach (PropertyInfo pi in propertys)
{
if (propertyNameList.Count == 0)
{
object obj = pi.GetValue(list[i], null);
tempList.Add(obj);
}
else
{
if (propertyNameList.Contains(pi.Name))
{
object obj = pi.GetValue(list[i], null);
tempList.Add(obj);
}
}
}
object[] array = tempList.ToArray();
result.LoadDataRow(array, true);
}
}
return result;
}

public class ReturnResult
{
/// <summary>
/// 消息类构造函数
/// </summary>
/// <param name="success"></param>
/// <param name="message"></param>
public ReturnResult(bool success, string message, string instanceId)
{
this.Success = success;
this.Message = message;
}

/// <summary>
/// 消息类构造函数
/// </summary>
/// <param name="success"></param>
/// <param name="message"></param>
public ReturnResult(bool success, string message)
: this(success, message, string.Empty)
{

}

public ReturnResult() { }

private bool success = false;
/// <summary>
/// 是否成功
/// </summary>
public bool Success
{
get { return success; }
set { success = value; }
}
private string message = string.Empty;
/// <summary>
/// 获取或设置系统返回消息
/// </summary>
public string Message
{
get { return message; }
set { this.message = value; }
}
}
}
}

C# Json解析Json = "{\"EX_RETURN\":[{\"MATNR\":\"test\"}] }";的更多相关文章

  1. json解析json字符串时候,数组必须对应jsonObjectArray,不能对应JsonObject。否则会解析错误。

    json第三方解析json字符串时候,json数组必须对应jsonObjectArray,不能对应JsonObject.->只要是[]开头的都是json数组字符串,就要用jsonArray解析 ...

  2. Json转model对象,model转json,解析json字符串

    GitHub链接: https://github.com/mozhenhau/D3Json D3Json 通过swift的反射特性,把json数据转换为model对象,本类最主要是解决了其他一般jso ...

  3. 认识Json解析json生成json

    .markdown-body hr::after,.markdown-body::after { clear: both } .loopLine,.messageLine0 { } .markdown ...

  4. c# 使用Newtonsoft.Json解析JSON数组

    一.获取JSon中某个项的值 要解析格式: [{"VBELN":"10","POSNR":"10","RET_ ...

  5. Newtonsoft.Json解析Json字符串案例:

    /// <summary> /// 上行jsom格式日志记录 /// </summary> /// <param name="responseJson" ...

  6. Newtonsoft.Json解析json字符串和写json字符串

    写: StringWriter sw = new StringWriter(); JsonWriter writer = new JsonWriter(sw); //如果报错则使用JsonWriter ...

  7. C# Newtonsoft.Json解析json字符串处理 - JToken 用法

    //*调用服务器API(获取可以处理的文件) //1.使用JSON通信协议(调用[待化验任务API]) String retData = null; { JToken json = JToken.Pa ...

  8. C# Newtonsoft.Json解析json字符串处理(最清晰易懂的方法)

    需求: 假设有如下json字符串: { ", "employees": [ { "firstName": "Bill", &quo ...

  9. Json 解析Json

    1.把LitJson导入到项目里面; 2.建一个下面的脚本,不挂在游戏对象上; 3.新建下面一个脚本,挂在相机上. using System.Collections; using System.Col ...

随机推荐

  1. day12.生成器;wraps初识

    生成器 在 Python 中,使用了 yield 的函数被称为生成器(generator). 跟普通函数不同的是,生成器是一个返回迭代器的函数,只能用于迭代操作,更简单点理解生成器就是一个迭代器. 在 ...

  2. python数据类型——数据转换

    数据类型有很多种,比如数值和字符,比如6和a,字符是需要加双引号的,下面的例子运行的结果是不一样的,数值会相加而字符会相连 print(6+6)print("6"+"6& ...

  3. 理解上下文Context

    --摘自<Android进阶解密> 知识点: 1.Context的使用场景 1)使用Context调用方法,比如启动Activity.访问资源.调用系统级服务等 2)调用方法时传入Cont ...

  4. LightOJ 1031 Easy Game (区间DP)

    <题目链接> 题目大意: 给定一段序列,两人轮流取数,每人每次只能从序列的两端的任意一段取数,取的数字位置必须连续,个数不限,问你这两人取数的最大差值是多少. 解题分析: 每人取数时面对的 ...

  5. CSS3_盒子背景

    盒子背景 盒子背景:content    padding    特殊的 boder 背景 背景绘制 从 padding 开始绘制 背景裁剪 background-clip(默认值 border-box ...

  6. linux学习:xargs与grep用法整理

    xargs xargs 是给命令传递参数的一个过滤器,也是组合多个命令的一个工具. xargs 可以将管道或标准输入(stdin)数据转换成命令行参数,也能够从文件的输出中读取数据. xargs 也可 ...

  7. 客户端无法加入域,报错:“无法与域‘xxx.com’的Active Directory域控制器(AD DC)链接” 请确保键入的域名正确

    1.客户端能不能解析到域名? nslookup 一下域名看看解析到的IP的地址 2.客户端的DNS要指向DC 3.客户端的相关服务,workstation,TCP/IP NetBios Helper, ...

  8. JavaFTP文件传输上传和下载文件

    首先在电脑上创建一个ftp服务器,具体步骤自行百度. 接下来开始写有用的java连接TFP站点和传输文件的代码. 1.首先jar用的是apache 的工具包 请自行下载 . 2.俩个文件代码 一个Ft ...

  9. Python基础之容器1----字符串和列表

    一.编码: 1.编码只是梳理 2.编码涉及的函数: 3.实例: 字符串内存图 二.字符串 1.定义:由一系列字符组成的不可变序列容器,存储的是字符的编码值. 不可变:指字符串一旦定义,其内存地址就已经 ...

  10. esyui datagrid 水平方向下方出来滚动条的原因是因为使用了同一列名

    esyui datagrid 水平方向下方出来滚动条的原因是因为使用了同一列名