我试图将以下代码片段从PHP转换为C#或VB.NET这是从用于从外部webhook捕获JSON字符串的PHP页面。将代码片段从PHP转换为C#或VB.NET
// 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字符串格式不在我的控制范围内,但我基本上需要获取“属性”节点。
只是谷歌“打开并阅读文件的C#”... – devHead
你有多远?发布一些C#/ VB.NET代码,你试过 – Bogdan
还没有得到很多,因为无法弄清楚我通过file_get_contents('php:// input'')的方式。我试图使用System.Net.WebClient – WhiskerBiscuit