0

I have the following string:

[{ "sources": ["https://graph.microsoft.com/v1.0/users?$count=true&$filter=startswith(displayName,'ConfRoom')"]}]

From this string, I need to parse the url:

https://graph.microsoft.com/v1.0/users?$count=true&$filter=startswith(displayName,'ConfRoom')

This is what I tried so far:

string query = "[{ "sources": ["https://graph.microsoft.com/v1.0/users?$count=true&$filter=startswith(displayName,'ConfRoom')"]}]"
var queryParts = JArray.Parse(query);
var currentPart = queryParts[0];
var url = currentPart.Value<JArray>("sources");
var urlAsString = Convert.ToString(url);

On running this, I see url as:

[ "https://graph.microsoft.com/v1.0/users?$count=true&$filter=startswith(displayName,'ConfRoom')" ]

How do I update the code to get the url as:

https://graph.microsoft.com/v1.0/users?$count=true&$filter=startswith(displayName,'ConfRoom')

user989988
  • 3,006
  • 7
  • 44
  • 91
  • Looks like you are asking how to parse json. does this help? https://stackoverflow.com/questions/6620165/how-can-i-deserialize-json-with-c – Nikolay Sep 20 '22 at 21:27
  • You knew how to unpack a json array when you did exactly that for the json array of the query. Then, when getting the sources array, you suddenly seem to have forgotten how to unpack a json array. How comes? Are you distracted? Are you a cat? ;-) –  Sep 20 '22 at 23:55
  • `Convert.ToString(url[0])` – BurnsBA Sep 21 '22 at 13:39
  • You can also check out these examples here for inserting string in .Net: https://learn.microsoft.com/en-us/dotnet/api/system.string.format?view=net-6.0#get-started-with-the-stringformat-method – Mehtab Siddique Sep 26 '22 at 08:40

0 Answers0