我有一个JSON对象(NewtonSoft.JObject).它包含以下格式的几个条目:
{
"id": "b65ngx59-2c67-4f5b-9705-8525d65e1b8",
"name": "TestSample",
"versions": []
},
{
"id": "8acd8343-617f-4354-9b29-87a251d2f3e7",
"name": "template 2",
"versions": [
{
"id": "556ng956-57e1-47d8-9801-9789d47th5a5",
"template_id": "8acd8343-617f-4354-9b29-87a251d2f3e7",
"active": 1,
"name": "1.0",
"subject": "<%subject%>",
"updated_at": "2015-07-24 08:32:58"
}
]
}
Run Code Online (Sandbox Code Playgroud)
注意:只是一个例子.
我编写了一个代码,以便在列表中获取ID:
List<JToken> templateIdList = jObj.Descendants()
.Where(t => t.Type == JTokenType.Property && ((JProperty)t).Name == "id")
.Select(p => ((JProperty)p).Value)
.ToList();
Run Code Online (Sandbox Code Playgroud)
注意:jObj是JSON对象
输出列表是:
[0] - b65ngx59-2c67-4f5b-9705-8525d65e1b8
[1] - 8acd8343-617f-4354-9b29-87a251d2f3e7
[2] - 556ng956-57e1-47d8-9801-9789d47th5a5
Run Code Online (Sandbox Code Playgroud)
它给所有我想要一个条件添加到LINQ使得只有在ids.Now template_ids含有活跃与价值在他们= 1应在列表中填充.
所需的输出:
[0] - 8acd8343-617f-4354-9b29-87a251d2f3e7
Run Code Online (Sandbox Code Playgroud)
我应该对linq查询进行哪些更改才能获得此信息?
编辑:完整的代码是
public bool CheckIfTemplateExists(string …
Run Code Online (Sandbox Code Playgroud) 我有两个对象,即卡和交易:
Card:
public string CardID {get; set;}
public string TransactionRef {get; set;}
Transaction:
public string TxnID {get; set;}
public string TxnDetails {get; set;}
Run Code Online (Sandbox Code Playgroud)
注:该TransactionRef
是格式的Date|TxnID
我还有两个对象的列表List<Card> cardDetails
和List<Transaction> transDetails
cardDetails:
{CardID = '1', TransactionRef = '20150824|Guid1'}
{CardID = '2', TransactionRef = '20150824|Guid2'}
{CardID = '3', TransactionRef = '20150824|Guid3'}
transDetails:
{TxnID = '23', TxnDetails = 'Guid1'}
{TxnID = '24', TxnDetails = 'Guid2'}
Run Code Online (Sandbox Code Playgroud)
我想使用基于TxnDetails的transDetails过滤cardDetails,以便过滤掉第二个列表中不包含TxnDetails的项目.
这应该是输出:
cardDetails:
{CardID = '3', TransactionRef = '20150824|Guid3'}
Run Code Online (Sandbox Code Playgroud)
我试过这样使用linq: …
我正在创建一个网站,其中有4个相同维度的div.如果我单击任何div,它将最大化以覆盖剩余的3个div.为此,我需要使用z-index属性.我没有在样式中指定z-index,只在单击任何div时使用jQuery添加它.这是我的div代码:
<div id="one" style="background: #58D3F7; height: 200px; width: 200px; position: absolute;
margin-left: 410px; margin-top: 202px; float: left; cursor: pointer; text-align: center;"></div>
Run Code Online (Sandbox Code Playgroud)
这里是用于最大化的jQuery代码:
$(function () {
var state = true;
$("#one").click(function () {
if (state) {
$("#one").animate({
height: 300,
top: -100
}, 1000);
$("#one").css({ "z-index": "1" });
$("#one").animate({
width: 300,
left: -100
}, 1000);
$("#itxt1").animate({
color: "#58D3F7"
}, 1000);
$("#one").animate({
height: 650,
width: 650
}, 1000);
} else {
$("#one").animate({
backgroundColor: "#58D3F7",
height: …
Run Code Online (Sandbox Code Playgroud) 使用C#我想基于一个公共属性组合列表中的项目.例如:
class Merchant
{
public string Name { get; set; }
public string Value1 { get; set; }
public string Value2 { get; set; }
public DateTime? Value3 {get; set; }
}
Run Code Online (Sandbox Code Playgroud)
列表包含:
{Name = "1", Value1 = "1", Value2 = "", Value3 = someDatetime}
{Name = "1", Value1 = "", Value2 = "2", Value3 = someDatetime}
{Name = "1", Value1 = "3", Value2 = "", Value3 = someDatetime}
{Name = "1", Value1 = "", Value2 = "4", Value3 = …
Run Code Online (Sandbox Code Playgroud) 大家好我想尝试以mvc3中的表格的形式将一些数据导出到excel.这是我用来生成excel文件的类:
//------------------------------------------------------------------------------
// <copyright file="ExcelDocument.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <summary>The Export to Excel Document class.</summary>
// ----------------------------------------------------------------------------
namespace ExporToExcel.Controllers.ControllerExtensions
{
using System;
using System.IO;
using System.Linq;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Extensions;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
/// <summary>
/// Excel document.
/// </summary>
public static class ExcelDocument
{
/// <summary>
/// Default spread sheet name.
/// </summary>
private const string DefaultSheetName = "Sheet1";
/// <summary>
/// Create the exel document for streaming.
/// </summary> …
Run Code Online (Sandbox Code Playgroud) 我必须从逗号分隔的字符串中获取不同的值.输入字符串可以包含重复的值.这是自动完成功能.例如:
我有一个字符串:shop,dell,image,just,just do,file,just,do,shop .... 我的要求是当我传递' jus '时,输出字符串应该是:" just,just do " .
我有一个表,我们将其称为 TempAccount,其中有一列名为 AccountID。它包含 1、2、3...等数字。
我的要求是我应该从前 10 个 AccountID 中选择最大值。
我知道我可以通过创建一个临时表并在其中插入前 10 个值,然后从该表中选择最大值来做到这一点。但我希望是否有任何直接查询可以用来实现这一目标。
就像是MAX(SELECT TOP 10 AccountID FROM TempAccount)
我实现这一目标的最佳方法是什么?
注意:我使用的是 SQL Server 2012
我有一个应用程序,其中数据从SQL DB获取并作为代理消息发送到服务总线.这些是步骤:
这是我面临的第三步.这是代码:
public async Task SendMessagesAsync(List<BrokeredMessage> brokeredMessageList)
{
try
{
var topicClient = CreateTopicClient();
await topicClient.SendBatchAsync(brokeredMessageList);
}
catch(Exception ex)
{
throw ex;
}
}
Run Code Online (Sandbox Code Playgroud)
当编译器使用SendBatchAsync方法时,它会在与Service Bus通信期间出现Error错误.检查连接信息,然后重试.内部例外是:
Internal Server Error: The server did not provide a meaningful reply; this might be caused by a premature session shutdown. TrackingId:some guid here
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试发送100条消息,它可以正常工作.我该怎么做才能让它一次发送1000条消息?
注意:每条消息大小为1445字节
您好,我正在创建一个具有 iFrame 和按钮的网站。该按钮的功能是获取 iFrame 中显示的任何内容的屏幕截图并将其保存为硬盘上的图像。以下是我正在使用的代码
private void saveURLToImage(string url)
{
if (!string.IsNullOrEmpty(url))
{
string content = "";
System.Net.WebRequest webRequest = WebRequest.Create(url);
System.Net.WebResponse webResponse = webRequest.GetResponse();
System.IO.StreamReader sr = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));
content = sr.ReadToEnd();
//save to file
byte[] b = Convert.FromBase64String(content);
System.IO.MemoryStream ms = new System.IO.MemoryStream(b);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
img.Save(@"c:\pic.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
img.Dispose();
ms.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
这是按钮单击的代码
protected void Button1_Click(object sender, ImageClickEventArgs e)
{
saveURLToImage("http://www.google.com");
}
Run Code Online (Sandbox Code Playgroud)
但是,当我单击按钮时,出现错误
The input is not a valid Base-64 string as it contains a non-base …
Run Code Online (Sandbox Code Playgroud) 我正在动态创建多个下拉列表(每个都有唯一的ID)并将它们绑定到面板.我还为它们编写了SelectedIndexChanged代码,每次更改下拉列表时都会触发它.我的问题是因为只有一个SelectedIndexChanged事件,我需要获取更改的下拉列表的ID.我怎么能得到它?
这是我将下拉列表绑定到面板的代码:
foreach (Document offer in parent.Children)
{
Panel pnlCat = new Panel();
pnlCat.ID = offer.Id.ToString();
pnlCat.CssClass = "ngx";
DropDownList ddl = new DropDownList();
ddl.ID = offer.Id + "_cat";
ddl.DataTextField = "catName";
ddl.DataValueField = "catId";
ddl.CssClass = "ddlStyle";
ddl.DataSource = category;
ddl.DataBind();
ddl.AutoPostBack = true;
ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
pnlCat.Controls.Add(ddl);
}
Run Code Online (Sandbox Code Playgroud)
这是SelectedIndexChanged代码:
void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
string id = this.ClientID;
}
Run Code Online (Sandbox Code Playgroud)
在id我得到"_page".我怎样才能获得下拉列表ID?
我正在将字符串反序列化为字典。这是反序列化的代码:
public T Deserialize<T>(string serialized)
{
var serializer = new DataContractSerializer(typeof(T));
StringReader reader = null;
try
{
reader = new StringReader(serialized);
using (XmlTextReader stm = new XmlTextReader(reader))
{
reader = null;
return (T)serializer.ReadObject(stm);
}
}
finally
{
if (reader != null)
{
reader.Dispose();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我传递输入字符串的方式:
string json = @"{""key1"":""value1"",""key2"":""value2""}";
Run Code Online (Sandbox Code Playgroud)
但是我在该行收到错误ReadObject(stm)
:
反序列化 System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version= 类型的对象时出错4.0.0.0,文化=中立,PublicKeyToken=b77a5c561934e089]]。根级别的数据无效。第 1 行,位置 1。
我尝试过这样输入:
string json = "[{'key1':'value1','key2':'value2'}]";
Run Code Online (Sandbox Code Playgroud)
但我仍然遇到同样的错误。我究竟做错了什么?
编辑:我无法更改反序列化方法,因为它是我的客户编写的方法。我只是编写单元测试来测试它。
我已经实现了语义日志记录,以将条目记录到azure表存储中.现在我想从azure表中删除旧的日志条目(比如说超过30天).问题是azure表中的partitionKeys和RowKeys是动态生成的.像这样的东西
PartitionKey RowKey
2519569987199999999 MyProjectName_2519569788418593594_FFFFFFF8 //entry date 20 october 2015
2519573205599999999 MyProjectName_2519573006928838932_FFFFFFE1 // entry date 16 october 2015
Run Code Online (Sandbox Code Playgroud)
我研究并发现PartitionKey的格式 DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks
如何从表中获取数据以进行删除?我需要进行全表扫描,因为partitionKey是动态的吗?
c# ×5
linq ×3
asp.net ×2
azure ×2
buttonclick ×1
csv ×1
dictionary ×1
html-select ×1
iframe ×1
jquery ×1
json ×1
json.net ×1
list ×1
logging ×1
openxml ×1
servicebus ×1
sql ×1
sql-server ×1