具有以下长控制器操作代码
@available = Available.find(694)
@tareservation_id = 8943
@request_date_time = Time.now.utc.iso8601
@request_id = Time.now.to_i
@in_date = (Date.today + 24.days).strftime("%Y-%m-%d").to_s
@book = %Q|{
"booking": {
"currencyCode": "USD",
"languageCode": "es",
"paxNationality": "ES",
"clientRef": {
"value": \"#{@tareservation_id}\",
"mustBeUnique": true
},
"items": [
{
"itemNumber": 1,
"immediateConfirmationRequired": true,
"productCode": \"#{@available.product_code}\",
"leadPaxName":
{ "firstName": "Guy",
"lastName": "Test"
},
"product":
{
"period":
{
"start": "2018-08-27",
"quantity": 2
}
}
} ]
},
"requestAuditInfo":
{ "agentCode": "001",
"requestPassword": "pass",
"requestDateTime": \"#{@requestDateTime}\",
"requestID": #{@request_id} },
"versionNumber": "2.0"
}|
然后必须在主体调用中将它作为JSON运送到API
@result = HTTParty.post(
'https://test.com/search',
:body => JSON.parse(@book).to_json,
headers: {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Connection' => 'Keep-Alive'
}
)
如果删除了以下块:
,
"product":
{
"period":
{
"start": "2018-08-27",
"quantity": 2
}
}
控制台JSON.parse(@start)
中的,可以正确解析。用块JSON::ParserError: 784: unexpected token
。但是我看不到这里有什么不对吗?
Rails处理字符串以用于将来的JSON转换是否真的严格限制语法,尤其是因为存在对实例变量的解释(包括字符串和整数),并且涉及har返回?那会是什么?还是有更安全的解决方案来摆脱迅速成为流沙的问题?
答案 0 :(得分:0)
事实证明,将太多行粘贴到控制台(在本例中为iTerm2)会对内存产生影响。在预期的行为情况下,最多可以观察到一次最多粘贴25行代码。