我已经阅读了很多有关此问题的Stack Overflow问题,但我仍然无法解决这个问题。 我从一个我无法控制的服务的webhook中获取以下JSON。我将数据读入PHP变量,如下所示:
$postData = file_get_contents('php://input');
我将$ postData输出到日志文件以查看POST请求的内容,如下所示:
{
"v": 1,
"matches_filters": {
"current": [
1,
10
]
},
"meta": {
"v": 1,
"action": "updated",
"object": "deal",
"id": 8918,
"company_id": 84041,
"user_id": 114674,
"host": "stonecreekinsurance.pipedrive.com",
"timestamp": 1446087218,
"permitted_user_ids": [
114674,
112820,
113033,
117102,
121983,
121984,
123453,
123454,
154367,
163389,
163390,
171541,
234921,
323973,
342136,
440511,
524205,
592218,
592222,
640371,
804841
],
"trans_pending": false,
"is_bulk_update": false,
"matches_filters": {
"current": [
1,
10
]
}
},
"retry": 0,
"current": {
"id": 8918,
"user_id": 114674,
"person_id": 7406,
"org_id": null,
"stage_id": 7,
"title": "test CallIn-EQ",
"value": 0,
"currency": "USD",
"add_time": "2015-10-28 23:48:04",
"update_time": "2015-10-29 02:53:38",
"stage_change_time": "2015-10-29 02:53:38",
"active": true,
"deleted": false,
"status": "open",
"next_activity_date": null,
"next_activity_time": null,
"next_activity_id": null,
"last_activity_id": null,
"last_activity_date": null,
"lost_reason": null,
"visible_to": "3",
"close_time": null,
"pipeline_id": 1,
"won_time": null,
"lost_time": null,
"products_count": null,
"files_count": null,
"notes_count": 1,
"followers_count": 1,
"email_messages_count": null,
"activities_count": null,
"done_activities_count": null,
"undone_activities_count": null,
"reference_activities_count": null,
"participants_count": 1,
"6edaf0488b13f9ab3090ce95e172e46224ef4742": null,
"e10aff12a449abfa1ae4826c65d23b9adcf82d10": null,
"41a5a8d9851c7aece2df16a7dfdbd3e2e8fcaac3": null,
"41da351210adc097ebe0c1cda00f3781f1b4855b": null,
"9d7875cfc9caa3e9b2aeef85f76eef2fdd65ebcd": "CallIn-EQ.com",
"expected_close_date": null,
"309c6f2061511f371c8f3036de6236b6f9ae3d5c": "9",
"20527ff9d907372c0df49f84caaa9a27ffe2fd0a": "(925)297-1234",
"17418ab9392d5820ce58de9efd8b03b428e4b389": "1234 Main St, Lafayette, CA 94549",
"17418ab9392d5820ce58de9efd8b03b428e4b389_lat": 37.8962173,
"17418ab9392d5820ce58de9efd8b03b428e4b389_long": -122.0599365,
"17418ab9392d5820ce58de9efd8b03b428e4b389_subpremise": "",
"17418ab9392d5820ce58de9efd8b03b428e4b389_street_number": "1234",
"17418ab9392d5820ce58de9efd8b03b428e4b389_route": "South Main Street",
"17418ab9392d5820ce58de9efd8b03b428e4b389_sublocality": "",
"17418ab9392d5820ce58de9efd8b03b428e4b389_locality": "Walnut Creek",
"17418ab9392d5820ce58de9efd8b03b428e4b389_admin_area_level_1": "California",
"17418ab9392d5820ce58de9efd8b03b428e4b389_admin_area_level_2": "Contra Costa County",
"17418ab9392d5820ce58de9efd8b03b428e4b389_country": "United States",
"17418ab9392d5820ce58de9efd8b03b428e4b389_postal_code": "94596",
"17418ab9392d5820ce58de9efd8b03b428e4b389_formatted_address": "1234 S Main St, Walnut Creek, CA 94596, USA",
"3eb9ff628e565bf9062b47344d64b71a28aefdae": null,
"046e70b421ff4227c2fe4330f446f7b6f25bd165": null,
"173d3e7db13eebd4c38b0a4044ce91e2af018553": null,
"327fd7256c8d9f2c4040c1c8b162a1fd4498875f": "12",
"fce5121c7c9a121fbcc181935b8c87d57de9540c": null,
"69768f3830c572afb53961d16be388b6b1f7716b": null,
"b843b47ebd27941af18d352d5b42f1550f04cf14": null,
"stage_order_nr": 2,
"person_name": "Test test",
"org_name": null,
"next_activity_subject": null,
"next_activity_type": null,
"next_activity_duration": null,
"next_activity_note": null,
"formatted_value": "$0",
"weighted_value": 0,
"formatted_weighted_value": "$0",
"rotten_time": "2015-11-08 02:53:38",
"owner_name": "Tom Lynch",
"cc_email": "censored",
"org_hidden": false,
"person_hidden": false
},
"previous": {
"id": 8918,
"user_id": 114674,
"person_id": 7406,
"org_id": null,
"stage_id": 6,
"title": "test CallIn-EQ",
"value": 0,
"currency": "USD",
"add_time": "2015-10-28 23:48:04",
"update_time": "2015-10-29 02:45:36",
"stage_change_time": "2015-10-29 02:45:36",
"active": true,
"deleted": false,
"status": "open",
"next_activity_date": null,
"next_activity_time": null,
"next_activity_id": null,
"last_activity_id": null,
"last_activity_date": null,
"lost_reason": null,
"visible_to": "3",
"close_time": null,
"pipeline_id": 1,
"won_time": null,
"lost_time": null,
"products_count": null,
"files_count": null,
"notes_count": 1,
"followers_count": 1,
"email_messages_count": null,
"activities_count": null,
"done_activities_count": null,
"undone_activities_count": null,
"reference_activities_count": null,
"participants_count": 1,
"6edaf0488b13f9ab3090ce95e172e46224ef4742": null,
"e10aff12a449abfa1ae4826c65d23b9adcf82d10": null,
"41a5a8d9851c7aece2df16a7dfdbd3e2e8fcaac3": null,
"41da351210adc097ebe0c1cda00f3781f1b4855b": null,
"9d7875cfc9caa3e9b2aeef85f76eef2fdd65ebcd": "CallIn-EQ.com",
"expected_close_date": null,
"309c6f2061511f371c8f3036de6236b6f9ae3d5c": "9",
"20527ff9d907372c0df49f84caaa9a27ffe2fd0a": "(925)297-1234",
"17418ab9392d5820ce58de9efd8b03b428e4b389": "1234 Main St, Lafayette, CA 94549",
"17418ab9392d5820ce58de9efd8b03b428e4b389_lat": 37.8962173,
"17418ab9392d5820ce58de9efd8b03b428e4b389_long": -122.0599365,
"17418ab9392d5820ce58de9efd8b03b428e4b389_subpremise": "",
"17418ab9392d5820ce58de9efd8b03b428e4b389_street_number": "1234",
"17418ab9392d5820ce58de9efd8b03b428e4b389_route": "South Main Street",
"17418ab9392d5820ce58de9efd8b03b428e4b389_sublocality": "",
"17418ab9392d5820ce58de9efd8b03b428e4b389_locality": "Walnut Creek",
"17418ab9392d5820ce58de9efd8b03b428e4b389_admin_area_level_1": "California",
"17418ab9392d5820ce58de9efd8b03b428e4b389_admin_area_level_2": "Contra Costa County",
"17418ab9392d5820ce58de9efd8b03b428e4b389_country": "United States",
"17418ab9392d5820ce58de9efd8b03b428e4b389_postal_code": "94596",
"17418ab9392d5820ce58de9efd8b03b428e4b389_formatted_address": "1234 S Main St, Walnut Creek, CA 94596, USA",
"3eb9ff628e565bf9062b47344d64b71a28aefdae": null,
"046e70b421ff4227c2fe4330f446f7b6f25bd165": null,
"173d3e7db13eebd4c38b0a4044ce91e2af018553": null,
"327fd7256c8d9f2c4040c1c8b162a1fd4498875f": "12",
"fce5121c7c9a121fbcc181935b8c87d57de9540c": null,
"69768f3830c572afb53961d16be388b6b1f7716b": null,
"b843b47ebd27941af18d352d5b42f1550f04cf14": null,
"stage_order_nr": 1,
"person_name": "Test test",
"org_name": null,
"next_activity_subject": null,
"next_activity_type": null,
"next_activity_duration": null,
"next_activity_note": null,
"formatted_value": "$0",
"weighted_value": 0,
"formatted_weighted_value": "$0",
"rotten_time": "2015-11-08 02:45:36",
"owner_name": "Tom Lynch",
"cc_email": "censored",
"org_hidden": false,
"person_hidden": false
},
"event": "updated.deal"
}
我通过jsonlint.com运行上面的JSON,它有效。我尝试使用一些其他SO问题中建议的substr($ postData,3)来摆脱字符串上的BOM编码,但这只是切断了我的JSON字符串的前3个字符。
var_dump(json_decode($postData,true) );
只返回空白。我可以看到,通过将json_decode($postData,true)
输出到变量然后记录变量来创建数组,但它完全为空。 json_last_error()
返回0,并且php error_log中没有显示警告或错误。
我不知道为什么JSON字符串没有正确地进入带有json_decode的数组...以及为什么json_last_error()将为0并且数组仍为空...任何帮助将不胜感激。< / p>