Link to home
Start Free TrialLog in
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

asked on

Extract the ID from a string

Hi Experts,
I have the following code.
StreamReader reader = new StreamReader(response.GetResponseStream());
string data = reader.ReadToEnd();

Open in new window


After I run "data" contains the following string
"results": [{
		"url": "https://www.zoo.com/api/chats/1906.2302191.RT8CHwd45iRXZ",
		"timestamp": "2019-06-11T23:22:33Z",
		"preview": "how can I add co workers to my account?\n",
		"type": "offline_msg",
		"id": "1906.2302191.RT8CHwd45iRXZ"
	}, {
		"url": "https://www.zoo.com/api/chats/1906.2302191.RT7kr6Nkhjk52",
		"timestamp": "2019-06-11T21:33:34Z",
		"preview": "I would like to order printer",
		"type": "offline_msg",
		"id": "1906.2302191.RT7kr6Nkhjk52"
	}
}]

Open in new window


I need help to extract all the IDs in a list or array.

For example, "1906.2302191.RT8CHwd45iRXZ", "1906.2302191.RT7kr6Nkhjk52"...
I am using C# and MVC
Thanks in advance!
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

ASKER

Thank you so much for your wonderful help!
powershelll
$json = '{
"results": [{
		"url": "https://www.zoo.com/api/chats/1906.2302191.RT8CHwd45iRXZ",
		"timestamp": "2019-06-11T23:22:33Z",
		"preview": "how can I add co workers to my account?\n",
		"type": "offline_msg",
		"id": "1906.2302191.RT8CHwd45iRXZ"
	}, {
		"url": "https://www.zoo.com/api/chats/1906.2302191.RT7kr6Nkhjk52",
		"timestamp": "2019-06-11T21:33:34Z",
		"preview": "I would like to order printer",
		"type": "offline_msg",
		"id": "1906.2302191.RT7kr6Nkhjk52"
	}
]}'
$data = @()
$data = (ConvertFrom-Json -InputObject $json)  | Select-Object -ExpandProperty results | Select-Object id 
$data

Open in new window