所以,我已经在网上到处查看并获得了一些关于如何解析JSON字符串然后将这些信息保存到特定变量的示例,但我对C#和Windows Phone 7开发非常陌生(仅执行了一周,但我因为我很熟悉C++,所以快速接收它.我无法理解我应该如何处理这个问题,所以我将只提供我要解析的代码和我到目前为止的代码.
我已经使用http://jsonlint.com/ Validator 验证了我的JSON信息.以下是我要解析的JSON信息(位于网站上):
[
{
"id": 19019,
"model": "tester",
"fields":
{
"name": "thename",
"slot": 45,
"category": "thecategory"
}
}
]
Run Code Online (Sandbox Code Playgroud)
这是我试图用来解析JSON信息并将其存储为变量的代码,以便我稍后可以在程序中调用该信息:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Resources;
using Microsoft.Phone.Controls;
using System.Collections.ObjectModel;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
namespace PhoneApp
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
}
private void myButton_Click(object sender, RoutedEventArgs e) …Run Code Online (Sandbox Code Playgroud) 是否有任何开源库可以在C#中将文本绘制成图像?我一直在TextRenderer和我一起玩,graphics.DrawString()但我从未接近获得不错的结果,我尝试了Smoothing,Interpolation,TextRenderHint的所有组合,但质量始终是半体面的.
这是一些图像,这是我最好的:

它需要如何看起来像:

这看起来很不错但是有些字符串似乎是字符间距错误,有些字母和字符串倾斜.
设置是:
objGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
objGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.GammaCorrected;
objGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
objGraphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
objGraphics.TextContrast = 0;
Run Code Online (Sandbox Code Playgroud)
格式是Png,背景是透明的,方法是TextRenderer.Drawtext().看起来像文字的厚度是错误的,我认为它是平滑的错误,当我尝试粗体文本它保持几乎相同,但只有字体大小〜10px.
我基本上想要输入一个字符串[]并且能够根据换行符进行foreach.我试过这样但我不相信这有用.
static string[] mystrings = {"here"+
"there"+
"mine"
}
Run Code Online (Sandbox Code Playgroud)
我想要预先知道并一次取回一个.这可能吗?
我在我的项目中有一段代码,我在另一个使用块中包含一个使用块,我想知道这是一个好习惯还是矫枉过正(请注意我明白这是一个非常简单的代码片段,它是仅用于说明目的):
protected void Submit_Click(object sender, EventArgs e)
{
try
{
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegConnectionString"].ConnectionString))
{
cn.Open();
string cmdStr = "SELECT COUNT(*) FROM REGISTRATION WHERE UserName ='" + this.TextBoxUN.Text + "' ";
using (SqlCommand selectUser = new SqlCommand(cmdStr, cn))
{
int temp = Convert.ToInt32(selectUser.ExecuteScalar().ToString());
if (temp == 0)
{
string insCmd = "Insert INTO REGISTRATION (UserName, Password, EmailAddress, FullName, Country) VALUES (@UserName, @Password, @EmailAddress, @FullName, @Country)";
using (SqlCommand insertUser = new SqlCommand(insCmd, cn))
{
try
{
insertUser.Parameters.AddWithValue("@UserName", this.TextBoxUN.Text);
insertUser.Parameters.AddWithValue("@Password", …Run Code Online (Sandbox Code Playgroud) 好的,我正在将一些我的Winform项目从Framework 4.0移动到Framework 4.5,我遇到了一个问题,试图从类库中找到可执行路径.我有一个错误日志记录类,我用来记录错误这里是我的代码片段:
using System;
using System.IO;
using System.Windows.Forms;
namespace FunctionClassLibrary
{
public static class ErrorLogging
{
public static string errLogFullPath
{
get
{
string errLogFile = "Application";
m_errLogFullPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), errLogFile + "_ErrorLog.txt");
return m_errLogFullPath;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我能够引用System.Windows.Forms命名空间,该命名空间反过来公开Application.ExecutablePath属性.显然,在Framework 4.5中,您不能再引用System.Windows.Forms命名空间.我一直在谷歌上搜索没有成功,这两个MSDN链接:LINK1和LINK2都显示使用System.Windows.Forms命名空间的示例.所以我的问题是,是否有人有解决此问题的方法?
好吧,我正在失去理智,我只是意识到我可以简单地使用Environment.GetFolderPath方法来查找CommonProgramFiles文件夹,这是我应该存储此文件的位置.抱歉打扰每个人今天早上.
多年来,我注意到Perl脚本中的SQL查询存在一些问题:
假设我有以下表格:
PET PET_TYPE COLOR
======== ========== ============
PET_ID PET_TYPE COLOR_ID
Name Description Description
Owner
PET_TYPE
COLOR_ID
Run Code Online (Sandbox Code Playgroud)
而且,我想找到所有的红狗,我将不得不产生以下SQL查询.
FIND PET_ID, Name, Owner
FROM PET, PET_TYPE, COLOR
WHERE COLOR_ID.Description = 'RED'
AND PET_TYPE.Description = 'DOG'
AND PET.COLOR_ID = COLOR.COLOR_ID
AND PET.PET_TYPE = PET_TYPE.PET_TYPE
Run Code Online (Sandbox Code Playgroud)
我想要一个简化生成查询的Perl模块.允许我创建数据库连接的东西,然后预定义表的链接方式.完成后,所有开发人员必须做的是简化查询.
我想像这样的接口:
#
# Create a new Database Connection
#
my $db = Some:Module->new(\%options);
#
# Now describe how these tables relate to each other.
# It should be possible to reuse this information for
# …Run Code Online (Sandbox Code Playgroud) 全部 - 我的一个课程中有这两种方法:
public static void DeSerializeFromXml(out cDBData db, string pathToXML)
{
using (XmlTextReader reader = new XmlTextReader(pathToXML))
{
XmlSerializer ser = new XmlSerializer(typeof(cDBData));
db = (cDBData)ser.Deserialize(reader);
}
}
public static void DeSerializeFromXml(out cDatabases db, string pathToXML)
{
using (XmlTextReader reader = new XmlTextReader(pathToXML))
{
XmlSerializer ser = new XmlSerializer(typeof(cDatabases));
db = (cDatabases)ser.Deserialize(reader);
}
}
Run Code Online (Sandbox Code Playgroud)
它们工作正常,但我想知道为什么我不能根据方法的返回类型创建方法重载.我以为我读到这可能在某个地方,但我显然是错的,因为它不起作用:
public static cDBData DeSerializeFromXml(string pathToXML)
{
cDBData db;
using (XmlTextReader reader = new XmlTextReader(pathToXML))
{
XmlSerializer ser = new XmlSerializer(typeof(cDBData));
db = (cDBData)ser.Deserialize(reader);
} …Run Code Online (Sandbox Code Playgroud) 全部 -
我能够恢复FullName值我试图从Active Directory检索电子邮件地址,但在我使用Windows身份验证的ASP.Net Web窗体项目中使用以下代码:
Dim wi As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent()
Dim a As String() = wi.Name.Split(New Char() {"\"c}) '' Context.User.Identity.Name.Split('\')
Dim ADEntry As System.DirectoryServices.DirectoryEntry = New System.DirectoryServices.DirectoryEntry(Convert.ToString("WinNT://" + a(0) + "/" + a(1)))
Dim Name As String = ADEntry.Properties("FullName").Value.ToString()
Dim Email As String = ADEntry.Properties("mail").Value.ToString()
Run Code Online (Sandbox Code Playgroud)
当我到达我试图检索电子邮件地址的代码行时,我得到一个"对象引用未设置为对象的实例".错误.我尝试过使用EmailAddress,电子邮件.我认为问题是我只是使用了错误的关键字.我能够检索FullName值.
所有的一切,我一直在墙上撞墙两天.我用google搜索和Google搜索,似乎无法找到解决方案.这是我有的:
我有两到六个不同的字符串数组(取决于用户的选择)但是对于这个问题,我们假设有3个单独的字符串数组:
我希望生成的数组包含这三个字符串数组的所有可能组合,但我不想组合同一列表中包含的值(不是:Tom Dick Harry).这就是我要看的结果数组:
我正在寻找一个VB6解决方案但我很欣赏大多数其他编程语言中的解决方案或算法.
提前感谢您的有用建议.
全部 - 我正在重构一些旧的代码,我正在寻找减少(或者如果不完全消除它)GoTo语句的方法.我有一段代码如下:
public void GetData()
{
TryAgain:
Foo foo = bar.GetData();
if(foo == null)
{
bar.addItem("Test");
goto TryAgain;
}
//Use the bar object
}
Run Code Online (Sandbox Code Playgroud)
用以下内容替换它:
public void GetData()
{
Foo foo = bar.GetData();
if(foo == null)
{
bar.addItem("Test");
GetData();
return;
}
//Use the bar object
}
Run Code Online (Sandbox Code Playgroud)
有任何想法或更好的方法来处理这个?
首先,这不是我的实际代码,为了简洁起见,我创建了这个代码片段.接下来请假设一旦将值添加到bar,则将绕过IF语句,代码部分将继续并使用bar对象.我想只创建一个方法,首先检查以确保bar对象不为null,如果不是,则继续运行方法中的其余代码.对困惑感到抱歉.
c# ×7
asp.net ×2
algorithm ×1
arrays ×1
dbi ×1
goto ×1
json ×1
overloading ×1
path ×1
perl ×1
permutation ×1
return-value ×1
sql-server ×1
string ×1
vb.net ×1
vb6 ×1
webforms ×1
winforms ×1