将 Json 复杂对象传递给 HttpPost 调用
Posted
技术标签:
【中文标题】将 Json 复杂对象传递给 HttpPost 调用【英文标题】:pass a Json complex object to a HttpPost Call 【发布时间】:2020-10-09 10:45:14 【问题描述】:所以,我是 Web 开发的新手,我有这个非常复杂的对象,其中包含许多由 javascript 函数填充的字段。 我需要将所有这些数据传递给 C#HttpPost Call。 我使用 JSON.Stringify 将我的所有数据转换为一个字符串,并制作了一个 Ajax call 将其传递给 C# 脚本,其中有一个包含所有预期字段的类,但一旦调用开始,我的输入始终为 Null。
我不明白问题是在ajax调用期间还是在httpPost方法内部,有人可以帮助一个可怜的n00b吗?
ajax 调用:
$.ajax(
type: "POST",
url: "/playlist",
data: jsonPlaylist
)
C#方法:
public class JsonController : Controller
[HttpPost]
[Route("playlist")]
public Playlist getJson([FromBody]string playlist)
Playlist myPlaylist;
if (playlist == null)
return null;
else
myPlaylist = JsonConvert.DeserializeObject<Playlist>(playlist);
return myPlaylist;
对象类:
public class Playlist
public struct chunk
public string id get; set;
public int sizeInBytes get; set;
public float[] times get; set;
public struct chunklist
public string averagetransfertSpeed get; set;
public string id get; set;
public int sizeInBytes get; set;
public float [] times get; set;
public chunk[] chunks get; set;
public string id get; set;
public string serverId get; set;
public string clientIp get; set;
public string clientRegion get; set;
public string networkcode get; set;
public int sizeInBytes get; set;
public float [] times get; set;
public float [] chunklistsBandwidth get; set;
public chunklist[] chunklists get; set;
这是 jsonPlaylist 的内容:
"id": "playlist.m3u8",
"chunklists": [
"id": "chunklist-f1-v1-a1.m3u8",
"times": [
2.4299999931827188,
0,
0
],
"chunks": [
"id": "seg-1-f1-v1-a1.ts",
"times": [
139.26500000525266,
0,
0
],
"sizeInBytes": 2671480
,
"id": "seg-2-f1-v1-a1.ts",
"times": [
179.73499998333864,
0,
0
],
"sizeInBytes": 3336248
,
"id": "seg-3-f1-v1-a1.ts",
"times": [
228.03500000736676,
0,
0
],
"sizeInBytes": 4259704
,
"id": "seg-4-f1-v1-a1.ts",
"times": [
145.17000000341795,
0,
0
],
"sizeInBytes": 2716600
,
"id": "seg-5-f1-v1-a1.ts",
"times": [
104.23500000615604,
0,
0
],
"sizeInBytes": 1874360
,
"id": "seg-6-f1-v1-a1.ts",
"times": [
183.2799999974668,
0,
0
],
"sizeInBytes": 3167800
,
"id": "seg-7-f1-v1-a1.ts",
"times": [
167.4300000013318,
0,
0
],
"sizeInBytes": 3098616
,
"id": "seg-8-f1-v1-a1.ts",
"times": [
159.42499999073334,
0,
0
],
"sizeInBytes": 2993336
,
"id": "seg-9-f1-v1-a1.ts",
"times": [
172.01999999815598,
0,
0
],
"sizeInBytes": 3243000
,
"id": "seg-10-f1-v1-a1.ts",
"times": [
174.45500000030734,
0,
0
],
"sizeInBytes": 3116664
,
"id": "seg-11-f1-v1-a1.ts",
"times": [
149.53999998397194,
0,
0
],
"sizeInBytes": 2833912
,
"id": "seg-12-f1-v1-a1.ts",
"times": [
177.34000002383254,
0,
0
],
"sizeInBytes": 3149752
,
"id": "seg-13-f1-v1-a1.ts",
"times": [
181.55000000842847,
0,
0
],
"sizeInBytes": 3363320
,
"id": "seg-14-f1-v1-a1.ts",
"times": [
188.6649999942165,
0,
0
],
"sizeInBytes": 3570872
,
"id": "seg-15-f1-v1-a1.ts",
"times": [
151.58999999403022,
0,
0
],
"sizeInBytes": 2854968
,
"id": "seg-16-f1-v1-a1.ts",
"times": [
140.3850000060629,
0,
0
],
"sizeInBytes": 2475960
,
"id": "seg-17-f1-v1-a1.ts",
"times": [
213.38999998988584,
0,
0
],
"sizeInBytes": 3847608
,
"id": "seg-18-f1-v1-a1.ts",
"times": [
15.46500000404194,
0,
0
],
"sizeInBytes": 250040
],
"sizeInBytes": 757,
"averageTransfertSpeed": "146.3282"
,
"id": "chunklist-f2-v1-a1.m3u8",
"times": [
0.7949999999254942,
0,
0
],
"chunks": [
"id": "seg-1-f2-v1-a1.ts",
"times": [
88.35000000544824,
0,
0
],
"sizeInBytes": 1600632
,
"id": "seg-2-f2-v1-a1.ts",
"times": [
97.8950000135228,
0,
0
],
"sizeInBytes": 1829240
,
"id": "seg-3-f2-v1-a1.ts",
"times": [
126.09999999403954,
0,
0
],
"sizeInBytes": 2313528
,
"id": "seg-4-f2-v1-a1.ts",
"times": [
78.01999998628162,
0,
0
],
"sizeInBytes": 1504376
,
"id": "seg-5-f2-v1-a1.ts",
"times": [
62.944999983301386,
0,
0
],
"sizeInBytes": 1185528
,
"id": "seg-6-f2-v1-a1.ts",
"times": [
98.8200000138022,
0,
0
],
"sizeInBytes": 1838264
,
"id": "seg-7-f2-v1-a1.ts",
"times": [
95.55499997804873,
0,
0
],
"sizeInBytes": 1745016
,
"id": "seg-8-f2-v1-a1.ts",
"times": [
96.30499998456798,
0,
0
],
"sizeInBytes": 1723960
,
"id": "seg-9-f2-v1-a1.ts",
"times": [
99.33500000624917,
0,
0
],
"sizeInBytes": 1811192
,
"id": "seg-10-f2-v1-a1.ts",
"times": [
117.35500002396293,
0,
0
],
"sizeInBytes": 1820216
,
"id": "seg-11-f2-v1-a1.ts",
"times": [
93.27000001212582,
0,
0
],
"sizeInBytes": 1675832
,
"id": "seg-12-f2-v1-a1.ts",
"times": [
106.61000001709908,
0,
0
],
"sizeInBytes": 1811192
,
"id": "seg-13-f2-v1-a1.ts",
"times": [
123.58500002301298,
0,
0
],
"sizeInBytes": 1922488
,
"id": "seg-14-f2-v1-a1.ts",
"times": [
106.47500000777654,
0,
0
],
"sizeInBytes": 2039800
,
"id": "seg-15-f2-v1-a1.ts",
"times": [
94.94999999878928,
0,
0
],
"sizeInBytes": 1615672
,
"id": "seg-16-f2-v1-a1.ts",
"times": [
81.07499999459833,
0,
0
],
"sizeInBytes": 1411128
,
"id": "seg-17-f2-v1-a1.ts",
"times": [
125.03000002470799,
0,
0
],
"sizeInBytes": 2229304
,
"id": "seg-18-f2-v1-a1.ts",
"times": [
7.4099999910686165,
0,
0
],
"sizeInBytes": 132728
],
"sizeInBytes": 757,
"averageTransfertSpeed": "142.9368"
,
"id": "chunklist-f3-v1-a1.m3u8",
"times": [
1.6149999864865094,
0,
0
],
"chunks": [
"id": "seg-1-f3-v1-a1.ts",
"times": [
54.34500001138076,
0,
0
],
"sizeInBytes": 1035128
,
"id": "seg-2-f3-v1-a1.ts",
"times": [
66.39999998151325,
0,
0
],
"sizeInBytes": 1140408
,
"id": "seg-3-f3-v1-a1.ts",
"times": [
83.42999999877065,
0,
0
],
"sizeInBytes": 1480312
,
"id": "seg-4-f3-v1-a1.ts",
"times": [
56.314999994356185,
0,
0
],
"sizeInBytes": 996024
,
"id": "seg-5-f3-v1-a1.ts",
"times": [
43.1549999921117,
0,
0
],
"sizeInBytes": 773432
,
"id": "seg-6-f3-v1-a1.ts",
"times": [
64.38500000513159,
0,
0
],
"sizeInBytes": 1167480
,
"id": "seg-7-f3-v1-a1.ts",
"times": [
59.35500000487082,
0,
0
],
"sizeInBytes": 1113336
,
"id": "seg-8-f3-v1-a1.ts",
"times": [
63.7249999854248,
0,
0
],
"sizeInBytes": 1119352
,
"id": "seg-9-f3-v1-a1.ts",
"times": [
63.30500001786277,
0,
0
],
"sizeInBytes": 1158456
,
"id": "seg-10-f3-v1-a1.ts",
"times": [
65.75000000884756,
0,
0
],
"sizeInBytes": 1161464
,
"id": "seg-11-f3-v1-a1.ts",
"times": [
58.2400000130292,
0,
0
],
"sizeInBytes": 1083256
,
"id": "seg-12-f3-v1-a1.ts",
"times": [
61.17500000982545,
0,
0
],
"sizeInBytes": 1161464
,
"id": "seg-13-f3-v1-a1.ts",
"times": [
65.2399999962654,
0,
0
],
"sizeInBytes": 1206584
,
"id": "seg-14-f3-v1-a1.ts",
"times": [
73.72499999473803,
0,
0
],
"sizeInBytes": 1317880
,
"id": "seg-15-f3-v1-a1.ts",
"times": [
57.865000009769574,
0,
0
],
"sizeInBytes": 1044152
,
"id": "seg-16-f3-v1-a1.ts",
"times": [
54.42500000935979,
0,
0
],
"sizeInBytes": 908792
,
"id": "seg-17-f3-v1-a1.ts",
"times": [
82.24999997764826,
0,
0
],
"sizeInBytes": 1441208
,
"id": "seg-18-f3-v1-a1.ts",
"times": [
4.824999981792644,
0,
0
],
"sizeInBytes": 78584
],
"sizeInBytes": 757,
"averageTransfertSpeed": "143.3341"
,
"id": "chunklist-f4-v1-a1.m3u8",
"times": [
1.7949999892152846,
0,
0
],
"chunks": [
"id": "seg-1-f4-v1-a1.ts",
"times": [
33.18499997840263,
0,
0
],
"sizeInBytes": 568888
,
"id": "seg-2-f4-v1-a1.ts",
"times": [
52.08000002312474,
0,
0
],
"sizeInBytes": 650104
,
"id": "seg-3-f4-v1-a1.ts",
"times": [
47.10500000510365,
0,
0
],
"sizeInBytes": 797496
,
"id": "seg-4-f4-v1-a1.ts",
"times": [
31.75500000361353,
0,
0
],
"sizeInBytes": 565880
,
"id": "seg-5-f4-v1-a1.ts",
"times": [
25.475000002188608,
0,
0
],
"sizeInBytes": 460600
,
"id": "seg-6-f4-v1-a1.ts",
"times": [
34.23000001930632,
0,
0
],
"sizeInBytes": 650104
,
"id": "seg-7-f4-v1-a1.ts",
"times": [
32.765000010840595,
0,
0
],
"sizeInBytes": 620024
,
"id": "seg-8-f4-v1-a1.ts",
"times": [
35.14500000164844,
0,
0
],
"sizeInBytes": 617016
,
"id": "seg-9-f4-v1-a1.ts",
"times": [
34.48000000207685,
0,
0
],
"sizeInBytes": 641080
,
"id": "seg-10-f4-v1-a1.ts",
"times": [
36.075000010896474,
0,
0
],
"sizeInBytes": 641080
,
"id": "seg-11-f4-v1-a1.ts",
"times": [
35.514999995939434,
0,
0
],
"sizeInBytes": 629048
,
"id": "seg-12-f4-v1-a1.ts",
"times": [
35.23999999742955,
0,
0
],
"sizeInBytes": 653112
,
"id": "seg-13-f4-v1-a1.ts",
"times": [
38.14999997848645,
0,
0
],
"sizeInBytes": 662136
,
"id": "seg-14-f4-v1-a1.ts",
"times": [
41.41999999410473,
0,
0
],
"sizeInBytes": 725304
,
"id": "seg-15-f4-v1-a1.ts",
"times": [
31.739999976707622,
0,
0
],
"sizeInBytes": 568888
,
"id": "seg-16-f4-v1-a1.ts",
"times": [
29.27500000805594,
0,
0
],
"sizeInBytes": 535800
,
"id": "seg-17-f4-v1-a1.ts",
"times": [
45.56999998749234,
0,
0
],
"sizeInBytes": 785464
,
"id": "seg-18-f4-v1-a1.ts",
"times": [
3.015000023879111,
0,
0
],
"sizeInBytes": 45496
],
"sizeInBytes": 757,
"averageTransfertSpeed": "139.5362"
],
"times": [
3.5700000007636845,
0,
0
],
"serverId": "servername",
"clientIp": "ip",
"clientRegion": "region",
"networkCode": " code",
"chunklistsBandwidth": [
2385338,
1351592,
855454,
461917
],
"sizeInBytes": 572
【问题讨论】:
你能把json和C#方法贴出来吗? 您好,欢迎来到 ***。请阅读How do I ask a good question? 和How to create a Minimal, Reproducible Example 并将缺失的信息添加到您的问题中。否则我们甚至无法猜测您的问题。 如果我们能看到你的控制器动作和你的js会更容易 我编辑并上传了一个对象的屏幕,另外两个超链接是ajax调用和c#方法的图像,第一次使用***,如果不是最好的演示,请见谅 Re:Edit 我直接加了代码 【参考方案1】:您也可以尝试像这样直接绑定对象:
public class JsonController : Controller
[HttpPost]
[Route("playlist")]
public Playlist getJson([FromBody]Playlist playlist)
if (playlist == null)
return null;
另外,请确保正确设置您的内容类型:
$.ajax(
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/playlist",
data: jsonPlaylist
)
使用这样的 JSON:
"id": "playlist.m3u8",
"chunklists": [
"id": "chunklist-f1-v1-a1.m3u8",
"times": [
2.4299999931827188,
0,
0
],
"chunks": [
"id": "seg-1-f1-v1-a1.ts",
"times": [
139.26500000525266,
0,
0
],
"sizeInBytes": 2671480
,
"id": "seg-2-f1-v1-a1.ts",
"times": [
179.73499998333864,
0,
0
],
"sizeInBytes": 3336248
,
"id": "seg-3-f1-v1-a1.ts",
"times": [
228.03500000736676,
0,
0
],
"sizeInBytes": 4259704
,
"id": "seg-4-f1-v1-a1.ts",
"times": [
145.17000000341795,
0,
0
],
"sizeInBytes": 2716600
,
"id": "seg-5-f1-v1-a1.ts",
"times": [
104.23500000615604,
0,
0
],
"sizeInBytes": 1874360
,
"id": "seg-6-f1-v1-a1.ts",
"times": [
183.2799999974668,
0,
0
],
"sizeInBytes": 3167800
,
"id": "seg-7-f1-v1-a1.ts",
"times": [
167.4300000013318,
0,
0
],
"sizeInBytes": 3098616
,
"id": "seg-8-f1-v1-a1.ts",
"times": [
159.42499999073334,
0,
0
],
"sizeInBytes": 2993336
,
"id": "seg-9-f1-v1-a1.ts",
"times": [
172.01999999815598,
0,
0
],
"sizeInBytes": 3243000
,
"id": "seg-10-f1-v1-a1.ts",
"times": [
174.45500000030734,
0,
0
],
"sizeInBytes": 3116664
,
"id": "seg-11-f1-v1-a1.ts",
"times": [
149.53999998397194,
0,
0
],
"sizeInBytes": 2833912
,
"id": "seg-12-f1-v1-a1.ts",
"times": [
177.34000002383254,
0,
0
],
"sizeInBytes": 3149752
,
"id": "seg-13-f1-v1-a1.ts",
"times": [
181.55000000842847,
0,
0
],
"sizeInBytes": 3363320
,
"id": "seg-14-f1-v1-a1.ts",
"times": [
188.6649999942165,
0,
0
],
"sizeInBytes": 3570872
,
"id": "seg-15-f1-v1-a1.ts",
"times": [
151.58999999403022,
0,
0
],
"sizeInBytes": 2854968
,
"id": "seg-16-f1-v1-a1.ts",
"times": [
140.3850000060629,
0,
0
],
"sizeInBytes": 2475960
,
"id": "seg-17-f1-v1-a1.ts",
"times": [
213.38999998988584,
0,
0
],
"sizeInBytes": 3847608
,
"id": "seg-18-f1-v1-a1.ts",
"times": [
15.46500000404194,
0,
0
],
"sizeInBytes": 250040
],
"sizeInBytes": 757,
"averageTransfertSpeed": "146.3282"
,
"id": "chunklist-f2-v1-a1.m3u8",
"times": [
0.7949999999254942,
0,
0
],
"chunks": [
"id": "seg-1-f2-v1-a1.ts",
"times": [
88.35000000544824,
0,
0
],
"sizeInBytes": 1600632
,
"id": "seg-2-f2-v1-a1.ts",
"times": [
97.8950000135228,
0,
0
],
"sizeInBytes": 1829240
,
"id": "seg-3-f2-v1-a1.ts",
"times": [
126.09999999403954,
0,
0
],
"sizeInBytes": 2313528
,
"id": "seg-4-f2-v1-a1.ts",
"times": [
78.01999998628162,
0,
0
],
"sizeInBytes": 1504376
,
"id": "seg-5-f2-v1-a1.ts",
"times": [
62.944999983301386,
0,
0
],
"sizeInBytes": 1185528
,
"id": "seg-6-f2-v1-a1.ts",
"times": [
98.8200000138022,
0,
0
],
"sizeInBytes": 1838264
,
"id": "seg-7-f2-v1-a1.ts",
"times": [
95.55499997804873,
0,
0
],
"sizeInBytes": 1745016
,
"id": "seg-8-f2-v1-a1.ts",
"times": [
96.30499998456798,
0,
0
],
"sizeInBytes": 1723960
,
"id": "seg-9-f2-v1-a1.ts",
"times": [
99.33500000624917,
0,
0
],
"sizeInBytes": 1811192
,
"id": "seg-10-f2-v1-a1.ts",
"times": [
117.35500002396293,
0,
0
],
"sizeInBytes": 1820216
,
"id": "seg-11-f2-v1-a1.ts",
"times": [
93.27000001212582,
0,
0
],
"sizeInBytes": 1675832
,
"id": "seg-12-f2-v1-a1.ts",
"times": [
106.61000001709908,
0,
0
],
"sizeInBytes": 1811192
,
"id": "seg-13-f2-v1-a1.ts",
"times": [
123.58500002301298,
0,
0
],
"sizeInBytes": 1922488
,
"id": "seg-14-f2-v1-a1.ts",
"times": [
106.47500000777654,
0,
0
],
"sizeInBytes": 2039800
,
"id": "seg-15-f2-v1-a1.ts",
"times": [
94.94999999878928,
0,
0
],
"sizeInBytes": 1615672
,
"id": "seg-16-f2-v1-a1.ts",
"times": [
81.07499999459833,
0,
0
],
"sizeInBytes": 1411128
,
"id": "seg-17-f2-v1-a1.ts",
"times": [
125.03000002470799,
0,
0
],
"sizeInBytes": 2229304
,
"id": "seg-18-f2-v1-a1.ts",
"times": [
7.4099999910686165,
0,
0
],
"sizeInBytes": 132728
],
"sizeInBytes": 757,
"averageTransfertSpeed": "142.9368"
,
"id": "chunklist-f3-v1-a1.m3u8",
"times": [
1.6149999864865094,
0,
0
],
"chunks": [
"id": "seg-1-f3-v1-a1.ts",
"times": [
54.34500001138076,
0,
0
],
"sizeInBytes": 1035128
,
"id": "seg-2-f3-v1-a1.ts",
"times": [
66.39999998151325,
0,
0
],
"sizeInBytes": 1140408
,
"id": "seg-3-f3-v1-a1.ts",
"times": [
83.42999999877065,
0,
0
],
"sizeInBytes": 1480312
,
"id": "seg-4-f3-v1-a1.ts",
"times": [
56.314999994356185,
0,
0
],
"sizeInBytes": 996024
,
"id": "seg-5-f3-v1-a1.ts",
"times": [
43.1549999921117,
0,
0
],
"sizeInBytes": 773432
,
"id": "seg-6-f3-v1-a1.ts",
"times": [
64.38500000513159,
0,
0
],
"sizeInBytes": 1167480
,
"id": "seg-7-f3-v1-a1.ts",
"times": [
59.35500000487082,
0,
0
],
"sizeInBytes": 1113336
,
"id": "seg-8-f3-v1-a1.ts",
"times": [
63.7249999854248,
0,
0
],
"sizeInBytes": 1119352
,
"id": "seg-9-f3-v1-a1.ts",
"times": [
63.30500001786277,
0,
0
],
"sizeInBytes": 1158456
,
"id": "seg-10-f3-v1-a1.ts",
"times": [
65.75000000884756,
0,
0
],
"sizeInBytes": 1161464
,
"id": "seg-11-f3-v1-a1.ts",
"times": [
58.2400000130292,
0,
0
],
"sizeInBytes": 1083256
,
"id": "seg-12-f3-v1-a1.ts",
"times": [
61.17500000982545,
0,
0
],
"sizeInBytes": 1161464
,
"id": "seg-13-f3-v1-a1.ts",
"times": [
65.2399999962654,
0,
0
],
"sizeInBytes": 1206584
,
"id": "seg-14-f3-v1-a1.ts",
"times": [
73.72499999473803,
0,
0
],
"sizeInBytes": 1317880
,
"id": "seg-15-f3-v1-a1.ts",
"times": [
57.865000009769574,
0,
0
],
"sizeInBytes": 1044152
,
"id": "seg-16-f3-v1-a1.ts",
"times": [
54.42500000935979,
0,
0
],
"sizeInBytes": 908792
,
"id": "seg-17-f3-v1-a1.ts",
"times": [
82.24999997764826,
0,
0
],
"sizeInBytes": 1441208
,
"id": "seg-18-f3-v1-a1.ts",
"times": [
4.824999981792644,
0,
0
],
"sizeInBytes": 78584
],
"sizeInBytes": 757,
"averageTransfertSpeed": "143.3341"
,
"id": "chunklist-f4-v1-a1.m3u8",
"times": [
1.7949999892152846,
0,
0
],
"chunks": [
"id": "seg-1-f4-v1-a1.ts",
"times": [
33.18499997840263,
0,
0
],
"sizeInBytes": 568888
,
"id": "seg-2-f4-v1-a1.ts",
"times": [
52.08000002312474,
0,
0
],
"sizeInBytes": 650104
,
"id": "seg-3-f4-v1-a1.ts",
"times": [
47.10500000510365,
0,
0
],
"sizeInBytes": 797496
,
"id": "seg-4-f4-v1-a1.ts",
"times": [
31.75500000361353,
0,
0
],
"sizeInBytes": 565880
,
"id": "seg-5-f4-v1-a1.ts",
"times": [
25.475000002188608,
0,
0
],
"sizeInBytes": 460600
,
"id": "seg-6-f4-v1-a1.ts",
"times": [
34.23000001930632,
0,
0
],
"sizeInBytes": 650104
,
"id": "seg-7-f4-v1-a1.ts",
"times": [
32.765000010840595,
0,
0
],
"sizeInBytes": 620024
,
"id": "seg-8-f4-v1-a1.ts",
"times": [
35.14500000164844,
0,
0
],
"sizeInBytes": 617016
,
"id": "seg-9-f4-v1-a1.ts",
"times": [
34.48000000207685,
0,
0
],
"sizeInBytes": 641080
,
"id": "seg-10-f4-v1-a1.ts",
"times": [
36.075000010896474,
0,
0
],
"sizeInBytes": 641080
,
"id": "seg-11-f4-v1-a1.ts",
"times": [
35.514999995939434,
0,
0
],
"sizeInBytes": 629048
,
"id": "seg-12-f4-v1-a1.ts",
"times": [
35.23999999742955,
0,
0
],
"sizeInBytes": 653112
,
"id": "seg-13-f4-v1-a1.ts",
"times": [
38.14999997848645,
0,
0
],
"sizeInBytes": 662136
,
"id": "seg-14-f4-v1-a1.ts",
"times": [
41.41999999410473,
0,
0
],
"sizeInBytes": 725304
,
"id": "seg-15-f4-v1-a1.ts",
"times": [
31.739999976707622,
0,
0
],
"sizeInBytes": 568888
,
"id": "seg-16-f4-v1-a1.ts",
"times": [
29.27500000805594,
0,
0
],
"sizeInBytes": 535800
,
"id": "seg-17-f4-v1-a1.ts",
"times": [
45.56999998749234,
0,
0
],
"sizeInBytes": 785464
,
"id": "seg-18-f4-v1-a1.ts",
"times": [
3.015000023879111,
0,
0
],
"sizeInBytes": 45496
],
"sizeInBytes": 757,
"averageTransfertSpeed": "139.5362"
],
"times": [
3.5700000007636845,
0,
0
],
"serverId": "servername",
"clientIp": "ip",
"clientRegion": "region",
"networkCode": " code",
"chunklistsBandwidth": [
2385338,
1351592,
855454,
461917
],
"sizeInBytes": 572
这就是邮递员的样子:
这就是我在 VS 上看到的:
【讨论】:
我试过了,但是打电话给 Postman 它会返回 415 不受支持的媒体类型 @Peru 我刚刚使用 Postman 对 VS 进行了快速测试,使用的代码与我发布的完全相同,然后在控制器中对其进行了序列化。你确定你发布的是正确的 JSON 吗?我必须在您的问题中添加左括号和右括号 是的,我必须删除 VScode 上的开/关括号以使其可读,否则它将是一个很长的单行,但对象本身实际上有它们。我发布的 json 是“let jsonPlaylist = JSON.stringify(playlist)”这一行的调试输出,所以我不明白为什么它不起作用,我是不是写的不好? @Peru 如果你得到我刚刚发布的 JSON,动作改变并将其作为带有原始正文 (JSON) 的 POST 放在 Postman 上,你还能得到 415 吗? 我复制粘贴了您的 json 并将其作为 jsonPlaylist 变量的内容,并在邮递员上调用了带有 raw-JSON 正文的 POST,但是是的,错误始终是 415,这可能是 som 标头问题吗?我在 c# 中添加了这个: using Microsoft.AspNetCore.Mvc;使用系统;使用 System.Collections.Generic;使用 System.Linq;使用 System.Threading.Tasks;使用 System.Text.Json;使用 System.Text.Json.Serialization;使用 Newtonsoft.Json;以上是关于将 Json 复杂对象传递给 HttpPost 调用的主要内容,如果未能解决你的问题,请参考以下文章
Angular2 http post没有将json对象传递给MVC 6控制器动作
如何将模型作为参数传递给 ASP.NET MVC 中的 [HttpPost] ActionMethod?
如何将 JSON 作为参数传递给控制器 .net api 中的 Post 方法