次のコードスニペットをPHPからC#またはVB.NETに変換しようとしています。これは、外部WebhookからJSON文字列をキャッチするために使用されるPHPページからのものです。
// 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:ストリームからjson文字列を取得しました。まだこれを解析する方法を理解しようとしています。JSON文字列形式は私の制御不能ですが、基本的に「プロパティ」ノードを取得する必要があります。