这是来自react原生文档的示例代码。
fetch('https://mywebsite.com/endpoint/', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
firstParam: 'yourValue',
secondParam: 'yourOtherValue',
})
})现在我想将两个类似数组的结构或数据发布到url,这些参数如下所示:
fetch('https://mywebsite.com/endpoint/', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
0: "{"fromCity":"Mumbai, IN - Chhatrapati Shivaji International (BOM)","toCity":"Goa, IN - Dabolim (GOI)","depart":"09-04-2017","returndate":"","adult":1,"child":0,"infant":0,"classoftravel":"E","prefferedairline":"AI","trip":"dom","tripType":"one way"}",
1: "[{"selectedOnwardFlight":[{"lstExtraServices":[],"flightDuration":"01:15","departuretime":"09-04-2017T13:30:00","arrivalairport":"GOI_Dabolim, Goa","freeBaggageAllowedWeight":25,"segment":1,"departureairport":"BOM_Chhatrapati Shivaji International, Mumbai","mac":"AI_Air India","fno":"663","dpartTerInfo":"2","oac":"AI","arrivaltime":"09-04-2017T14:45:00"}],"selectedReturnFlight":[],"selectedThirdFlight":[],"selectedFourthFlight":[],"selectedFifthFlight":[],"airlineLogoPath":"AI.png","airlineName":"Air India","airlineRecommend":"N","airlinecode":"AI","faretype":"Refundable","flightsID":"0","nonStop":"Y","onduration":[["0:1:15"],["NA"],["0:1:15"],["NA"],"Chhatrapati Shivaji International, Mumbai",0],"reduration":[],"thirdduration":[],"fourthduration":[],"fifthduration":[],"fare":[{"lstExtraServices":[],"ibp":"0","cbp":"0","tp":"6528","pc":"AI","fareBasisDetails":[{"paxType":"ADULT","fareBasisCode":"TAP15B","segment":"1-663","fareType":"Refundable","rbd":"T","breakPoint":"Y"}],"fareClassType":"Economy","taxDetails":{"itaxdetails":[],"ctaxdetails":[],"atax":"496","ctax":"0","ttax":"496","itax":"0","ataxdetails":[{"name":"YR","value":"70"},{"name":"IN","value":"0"},{"name":"WO","value":"150"},{"name":"YM","value":"138"},{"name":"JN","value":"128"},{"name":"xt","value":"10"}]},"abp":"2200"}],"vendor":"amadeus","totalprice":"2713","originaltp":"2696","serviceTax":17}]",
})
})但是这是不起作用的,如何在post fetch method.While attaching.Please中发布两件事注意那0:和1:描述两个独立的json值的事情
发布于 2017-04-07 04:33:03
问题是你的JSON是无效的--像0这样的属性应该加引号,例如JSON.stringify({"0":...,然后你在对象标识符的开头加上一个引号{0:"{"fromCity“... --> this应该是{"0":{"fromCity”...
以下是正确设置邮件第一部分格式的示例:
{ "0":{"fromCity ":“孟买,IN - Chhatrapati Shivaji国际(印度) ","toCity ":”果阿,IN -达博林“,"depart ":"09 - 04 - 2017”,
和属性1的开始:
"1":[{"selectedOnwardFlight ":[{"lstExtraServices ":[]
等
对JSON进行排序的一个很好的站点是jsonlint.com。
https://stackoverflow.com/questions/43261761
复制相似问题