Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SelectToken() with whitespace in path

I recently upgraded from Json.Net 50r6 to 60r6. Consider the following json:

{
    "room list": {
        "regular": [
            {
                "single": {
                    "beds": 1,
                    "bedtype": "double",
                    "balcony": "no"
                }
            }, {
                "double": {
                    "beds": 2,
                    "bedtype": "double",
                    "balcony": "no"
                }
            }
        ]
    }
}

In 50r6, this code snippet works correctly:

    Dim j As JObject = JObject.Parse(line)

    Dim jt As JToken = j.SelectToken("room list")

In 60r6, I get an error:

"Unexpected character while parsing path: "

Is this a bug? The issue resolves in 60r6 if I change the json and SelectToken() method to "roomlist".

Edit: I also get the same error with SelectToken() if the passed parameter contains a parenthesis.

like image 619
zetetic Avatar asked Dec 10 '14 10:12

zetetic


People also ask

How to extract tokens from string of words without whitespace in Python?

Python NLTK | nltk.WhitespaceTokenizer Last Updated : 07 Jun, 2019 With the help of nltk.tokenize.WhitespaceTokenizer () method, we are able to extract the tokens from string of words or sentences without whitespaces, new line and tabs by using tokenize.WhitespaceTokenizer () method. Syntax : tokenize.WhitespaceTokenizer ()

What is selecttoken in LINQ?

SelectToken () provides a method to query LINQ to JSON using a single string path to a desired JToken . SelectToken makes dynamic queries easy because the entire query is defined in a string.

How do I get the child token of a jtoken?

SelectToken SelectToken is a method on JToken and takes a string path to a child token. SelectToken returns the child token or a null reference if a token couldn't be found at the path's location. The path is made up of property names and array indexes separated by periods, e.g. Manufacturers.Name.

How do I escape spaces in a file name using PowerShell?

This solution works both in the traditional Command Prompt (CMD) environment and in Windows PowerShell. In the Command Prompt, the caret character ( ^ ) will let you escape spaces—in theory. Just add it before each space in the file name. (You’ll find this character in the number row on your keyboard. To type the caret character, press Shift+6.)


1 Answers

Change it to:

Dim jt As JToken = j.SelectToken("['room list']")
like image 105
James Newton-King Avatar answered Oct 14 '22 04:10

James Newton-King