2

In C# I'm using UriBuilder to build a GET request. Works fine except for where the query string needs to represent a string array using square brackets notation. How do I do that?

The data to form the query is in the form: string[] obs_section

The query string needs to look like (e.g.): 'obs_section':['a','b','c']

I tried:

Query["obs_section"] = JsonConvert.SerializeObject(obs_section)

but that gives the wrong format.

Here is what a working example query in Python looks like. I'm trying to replicate in C#:

entry = requests.get("https://filtergraph.com/aavso/api/v1/targets",auth=(userid,password),params={'obs_section':['a','b','c']})

1 Answer 1

1

You can use string.Join() to join an array and make a string:

string QS = $"'obs_section':[{string.Join(",",obs_section.Select(x => $"'{x}'"))}]";

Here is a Live Demo of how it works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.