Parsing JSON string with Chinese character [closed] - vb.net

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
The are various question similar to my problem I have found on SO but none of them are able to solve the issue I am having. I have been provided a text file which contains the following string,
callback12({
"searchResult":{
"data":[
{
"CURRENCY":"人民币",
"DATE":"2016-03-25",
"NAME":"仲尧文"
},
{
"CURRENCY_TYPE":"人民币",
"DATE":"2016-03-24",
"NAME":"王新华"
}]
}
})
I am using following line of code to parse the JSON string,
Dim objTempResults As JObject = JObject.Parse(strSource)
Dim objResults = objTempResults("callback12")("searchResult")("data").Children()
But it is giving me the exception on JObject.Parse that,
Unexpected character encountered while parsing value: \. Path '', line 0, position 0.
The other questions that I have found have answers to encode and decode the string but I cannot encode or decode the whole string as there are only two fields which needs to be encoded. How can I solve this exception?

The Chinese characters in the JSON are not the problem here. You are getting a parse error because your JSON is wrapped inside a javascript function call, which makes it invalid JSON. (See JSON.org for details on what is considered valid JSON syntax.) If you remove the callback12() surrounding the JSON, it will parse correctly with Json.Net.
Fiddle: https://dotnetfiddle.net/xN5JJi

Related

VB.NET Substring function broken [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have a problem with Substring function. As you can see on Watch window shcreenshot I have the variable called val equal to ‎03.‎09.‎2015 ‏‎17:30
I do not understand why but
val.Substring(0,2) returns 0 instead of 03
val.Substring(0,3) returns 03 (string of two symbols)
What am I doing wrong?
Your string contains non-printable characters. Note the following from your screenshot:
val = "03.09.2015 17:30"
val.Length = 21
However, 03.09.2015 17:30 only has 16 characters. Thus, the string contains other, zero-width characters.
To find the culprit, output a hex dump of your problematic string and compare it with the hex dump of the literal string 03.09.2015 17:30.
From OP comment:
The original problem was with Parse (and Parse-like) functions. It can not parse this string as Date or DateTime
Once the invisible characters are removed from the string, it certainly can be parsed:
Dim d As Date = DateTime.Parse("03.09.2015 17:30", Globalization.CultureInfo.InvariantCulture)
Dim m As Integer = d.Month ' m = 3
Of course, choose the particular Parse method that best fits your needs.

Convert Really Long Number String To INT64 [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
Trying to convert a number string into an INT64 in VB.NET. The number I am testing with is 12804494279291877304.
The error I am getting is "Value was either too large or too small for an Int64."
Code sample below.
BigInt = CLng(EncodeNumber)
It's too big, doesn't fix in a INT64. It would fit in a UINT64.
Dim v As UInt64
v = UInt64.Parse("12804494279291877304")
Like #Çöđěxěŕ said, using TryParse allow the use of proper error handling.
If Not UInt64.TryParse("12804494279291877304", v) Then
' Handle wrong input
End If
Your number is too big for Int64, so you could use BigInteger, please see https://learn.microsoft.com/en-us/dotnet/api/system.numerics.biginteger?view=netframework-4.8
You can use unsigned Int64 as others suggest but beware that it won't hold negative numbers and also has a limit of 18446744073709551615

Qlikview - Peek() function in FOR loop not working [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have table like this:
TABLE:
LOAD * INLINE [
SERVER
'SERVERNAME1'
'SERVERNAME2'
...
];
and loop:
FOR i = 1 to NoOfRows('TABLE')
LET v_TABLE = Peek('SERVER', $(i), 'TABLE');
LET v_SPECIFICATION = FieldName(1, $(v_TABLE));
trace $(v_TABLE);
...
STATEMENTS
...
NEXT
If I reload it, nothing happen, although for cycle runs thousand times, because the result of Peek() funcion is always NULL, not the value from table. Is the syntax incorrect, or is there some other mistake?
Sorry, my question was wrong. In Peek() function the third parameter wasn't string, but a variable (I didnt know that this will be mistake) and after many tries, I found out two things:
in my QV version 11.20 I have to call functions with variable parameter e.g. v_SPECIFICATION, not $(v_SPECIFICATION) (but not variable $(i), why???)
and rows in tables are numbered from zero (sometimes, as well), so this works for me:
LET v_TABLE = Peek('SERVER', $(i) - 1, v_SPECIFICATION);
Its really strange for me, but learning by doing...

String.Format For SQL Connection String [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I need to convert a SQL connection string into a String.Format line
The line that I need to convert is this:
WHERE full_name = #FullGraveNumber AND cemetery_id = #CemeteryID
Both thefull_name and cemetery_id are variables, but I have not idea how to construct the
String.Format line.
Seems you are looking for
Dim selectCommand = "SELECT * FROM mytable WHERE full_name = #FullGraveNumber AND cemetery_id = #CemeteryID"
Dim cmd = New SqlCommand(selectCommand, yourconnetion)
cmd.Parameters("#FullGraveNumber").Value = value1
cmd.Parameters("#CemeteryID").Value = value2
or
cmd.Parameters.AddWithValue("#FullGraveNumber", value)
First of all, ConnectionString is already a String with no parameters, it does not need to converted using String.Format. Usually stored in app.config, you feed it directly into SqlConnection object upon creation.
Part of the query that you have is also a String, but this time it may be substituted with parameters. However, please don't do so and use SQL parameters instead (see #huMpty's answer).
full_name and cemetery_id are SQL parameters, variables is something else.
My suggestion it to learn the terminology first, before you do any coding. No offense, it would benefit you a lot, because you would be able to ask a proper question. Proper question means a fast and qualified answer. Improper questions are usually closed. These are the rules of StackOverflow.

How to store specific part of youtube URL - VB [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a form with a textbox. In the textbox the user will insert a youtube link such as: 'https://www.youtube.com/watch?v=IJNR2EpS0jw' . However I only need this part of the URL 'youtube.com/watch?v=IJNR2EpS0jw' . So my question is how can I write a code to store the selected part of the URL I need. I think it needs to start of like this:
Dim specificurl As String
specificurl = TextBox1.Text.StartsWith("youtube.com")
Regards
You can use the String.Replace method to strip the https://www. out of the string.
Dim URLString As String = "http://www.youtube.com/watch?v=..."
URLString = URLString.Replace("https://www.", "")
URLString = URLString.Replace("http://www.", "")
This will get you the value you're looking for.
If there's any chance your input may have capital letters (unlikely since this is a URL), you'd need to use Regex to do the replacement (this would also let you do both HTTP and HTTPS in one line):
Dim newValue As String = Regex.Replace(input, "^https*://", String.Empty,
RegexOptions.IgnoreCase)