-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using "_xpath" on table with one row does not create an JSON array #25
Comments
// ...
JContainer scrapingResults = openScraping.Extract(html);
if (scrapingResults["row"].GetType() == typeof(JObject))
{
JArray container = new JArray
{
scrapingResults["row"]
};
scrapingResults["row"] = container;
}
Console.WriteLine(JsonConvert.SerializeObject(scrapingResults, Formatting.Indented)); |
Did you try to use _forceArray option? |
Something like this: "title":
{
"_xpath": "//h1",
"_forceArray": true
} |
Thank You! It works like a charm. 😄 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The _xpath feature seems to behave differently if there is only one result from the _xpath. It will generate:
"rows": { "col1": "val1", "col2": "val2" }
Instead of:
"rows": [{ "col1": "val1", "col2": "val2" }]
This makes it difficult to iterate over the array of rows, as you end up iterating over the columns. Thoughts? Is there a way to force it to be an array regardless of there being a single row? Thank you.
The text was updated successfully, but these errors were encountered: