如何获取其中有多行的对象值
我正在将JSON
string转换为对象,并且此对象包含像行结构一样的多个表的logging。 每行包含一些设置值。 这就像对象内的一个对象。 我试图读取这些对象的价值,但我不成功。
WebResponse response = request.GetResponse(); Stream responseStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(responseStream); // Read the content. string responseFromServer = reader.ReadToEnd(); //converting json data into array JavaScriptSerializer ss = new JavaScriptSerializer(); object itm = ss.DeserializeObject(responseFromServer);
在这个响应stream对象给多个值的jsonstring,我转换成使用javascriptserializer对象。 在debugging模式下,我已经看到所有的数据在这个对象中有多行,其中每一行本身也是一个对象。
这些行存储信息,如offer_id,名称作为键和值。 我想写一个循环来调用这个键和它的值来执行进一步的操作。 但是我无法在循环中调用这些数据。
通常我会使用JavaScriptSerializer的方式是
//Serialise JavaScriptSerializer js = new JavaScriptSerializer(); string str = js.Serialize(new Thing() { ID = "111" }); //Deserialise Thing thing = js.Deserialize<Thing>(str);
但是如果你不知道types转换回你可以
Dictionary<string, object> dic = (Dictionary<string, object>)js.DeserializeObject(str); foreach (KeyValuePair<string, object> keyValue in dic) { keyValue.Key; <-- this is the property name (ID) keyValue.Value; <-- this is the property value ("111") }
然后只处理您收到的键值对。
- 防止Excel更新C#中的屏幕
- 如何使用asp.net C#将Html表格下载到excel文件
- 以编程方式将单元格格式化为checkbox
- Office 2013 c#加载项 – 空工作簿对象HRESULT:0x800A03EC错误
- 从MS Excel vba代码调用c#dll – 编译错误:未find方法或数据成员
- 在将Excel文件中的数据转换为XML时,将点隐式转换为散列
- 如果系统date时间格式发生更改,则在SQL Server中保存错误
- 无法将“System .__ ComObject”转换为“System.Web.UI.WebControls.ListItem”
- 有没有办法使用C#/ EPPlus为Excel图表设置网格线选项