I'm trying to convert the following code snippet from PHP to C# or VB.NET This is from a PHP page which is used to catch a JSON string from an external webhook.
// Get the POST body from the Webhook and log it to a file for backup purposes...
$request_body = file_get_contents('php://input');
$myFile = "testfile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $request_body);
fclose($fh);
// Get the values we're looking for from the webhook
$arr = json_decode($request_body);
foreach ($arr as $key => $value) {
if ($key == 'properties') {
foreach ($value as $k => $v) {
foreach ($v as $label => $realval) {
if ($label == 'value' && $k == 'zip') {
$Zip = $realval;
}
elseif($label == 'value' && $k == 'firstname') {
$Fname = $realval;
}
elseif($label == 'value' && $k == 'lastname') {
$Lname = $realval;
}
elseif($label == 'value' && $k == 'email') {
$Email = $realval;
}
elseif($label == 'value' && $k == 'phone') {
$Phone = $realval;
$Phone = str_replace("(", "", $Phone);
$Phone = str_replace(")", "", $Phone);
$Phone = str_replace("-", "", $Phone);
$Phone = str_replace(" ", "", $Phone);
}
//need the other values as well!
}
}
}
}
ETA: I've got the json string from the stream now. Still trying to figure out how to parse this. The JSON string format is out of my control, but I essentially need to get the "properties" node.