字符常量必须包含一个字符。 [英] Character constant must contain exactly one character.

查看:454
本文介绍了字符常量必须包含一个字符。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在带下划线的部分出错:

Getting an error on the underlined parts:

"Character constant must contain exactly one character."




Dim serializer = New System.Web.Script.Serialization.JavaScriptSerializer()
Dim datae As List(Of datapart) = serializer.Deserialize(Of List(Of datapart))(datar)
For Each element In datae
    oo += 1
    dataa(oo, 1) = Convert.ToInt32(element.id)
    datestring(oo) = element.datetime
    dataa(oo, 2) = Convert.ToInt32(element.col1)
    dataa(oo, 3) = Convert.ToInt32(element.col2)
    dataa(oo, 4) = Convert.ToInt32(element.col3)
Next
Dim returndata As New List(Of datapart)()
For i As Integer = 1 To oo
    If datestring(i) = date1 Then
        json1 = "[{" + "\"" + "id" + "\"" + ":" + dataa(i, 1) + "," + "\"" + "datetime" + "\"" + ":" + datestring(i) + "," + "\"" + "col1" + "\"" + ":" + dataa(i, 2) + "," + "\"" + "col2" + "\"" + ":" + dataa(i, 3) + "," + "\"" + "col3" + "\"" + ":" + dataa(i, 3) + "}]"
    End If
Next
Return serializer.Serialize(json1)





什么我试过了:



将所有类整数设为整数和类字符串字符串。



What I have tried:

Made all the class integers to integers and class strings strings.

推荐答案

嗯...在VB.NET中,如果必须在字符串中加引号,则转义序列是连续的两个引号字符。 VB.NET不知道什么是\\意味着,C#没有。



另外,你真的不必使用所有的字符串连接。你可以简化它非常容易。哦,VB.NET中的连接是用'&'而不是'+'完成的。

Ummm... in VB.NET, if you must put quotes in a string, the escape sequence is two quote characters in a row. VB.NET doesn't know what \" means, C# does.

Also, you really don't have to use all that string concatenation. You can simplify it quite easily. Oh, and concatenation in VB.NET is done with '&', not '+'.
json1 = "[{""" + id + "":" & dataa(i, 1) & ",""datetime"":" & datestring(i) & ...



但是,为什么你甚至组装一个像这样的json字符串?如果您创建了一个适当的数据模型来序列化为json,那将会更加灵活。然后你就不会乱用这样的字符串。



你打电话给 serializer.Serialize(json1)没有序列化数据。它正在序列化您组装的字符串。两者不一样。


But, why are you even assembling a json string like that? It would be far more flexible had you created an appropriate data model to serialize to json. Then you wouldn't be messing around with strings like this at all.

You're call to serializer.Serialize(json1) isn't serializing the data. It's serializing the string you assembled. The two are NOT the same.


这篇关于字符常量必须包含一个字符。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆