我正在使用C作为我的程序.我正在使用Ubuntu 14.04.以下是我使用的循环之一.
for (x=0; x<1024; x++)
{
for (i=0; i<8; i++)
{
for (j=0; j<8; j++)
{
arr[x][i][j]=vi[8*i+j+gi];
}
}
gi = gi+(8*8);
}
Run Code Online (Sandbox Code Playgroud)
这里'vi'是一个单维数组.现在数组'arr'有1024块大小为8x8的块.是否有规定在循环外部访问块(大小为8x8)以进行进一步处理?
我很难理解为什么在调用Hash#merge函数时我的Hash被视为String .在调用以下代码时,我会收到一个NoMethodError method 'merge' for #<String:0x000...
抛出错误的代码行如下:topic.publish({subject: 'LAB_COMPLETE', message: lab_attribs.merge(full_name: current_user.full_name)}.to_json).出于某种原因,Ruby将lab_attribs变量视为String而不是Hash.根据下面的来源,我不可能看到这是怎么回事.
lab_attribs = {
name: create_params['lab_name'],
completed: DateTime.now,
duration: create_params['duration'],
final_grade: create_params['final_grade'],
cpe: create_params['cpe'],
user_id: create_params['user_id']
}
lab = Lab.new(lab_attribs)
if lab.save
logger.debug("lab_attribs class: #{lab_attribs.class}, lab_attribs value: #{lab_attribs}" )
sns = Aws::SNS::Resource.new
topic = sns.topic(Rails.application.secrets.lab_results_topic)
topic.publish({subject: 'LAB_COMPLETE', message: lab_attribs.merge(full_name: current_user.full_name)}.to_json)
render json: { lab_name: lab.name }
else
render json: { status: 422, errors: lab.errors }
end
Run Code Online (Sandbox Code Playgroud)
logger.debug 输出以下内容:
lab_attribs class: …Run Code Online (Sandbox Code Playgroud) 哈希
data = {
:recordset => {
:row => {
:property => [
{:name => "Code", :value => "C0001"},
{:name => "Customer", :value => "ROSSI MARIO"}
]
}
},
:@xmlns => "http://localhost/test"
}
Run Code Online (Sandbox Code Playgroud)
使用的代码
result = data[:recordset][:row].each_with_object([]) do |hash, out|
out << hash[:property].each_with_object({}) do |h, o|
o[h[:name]] = h[:value]
end
end
Run Code Online (Sandbox Code Playgroud)
我无法得到以下输出:
[{"Code"=>"C0001", "Customer"=>"ROSSI MARIO", "Phone1"=>"1234567890"}
Run Code Online (Sandbox Code Playgroud)
错误信息:
TypeError没有将Symbol隐式转换为Integer
它可以在多记录的情况下正常工作
data = {
:recordset => {
:row => [{
:property => [
{:name => "Code", :value => "C0001"},
{:name => "Customer", …Run Code Online (Sandbox Code Playgroud) 我正在通过NY Times API在网页上显示一些数据,但我只希望显示前4条文章。我如何只显示前4个,其余的在JavaScript中消失呢?
我还没有尝试过任何可能的解决方案,因为我真的不知道该怎么做。
这是我从API中显示的一些数据,但报纸上有20篇热门新闻,我只想显示4个。

let html = [];
fetch('https://api.nytimes.com/svc/topstories/v2/technology.json?api-key=...')
.then((resp) => resp.json())
.then(function(data) {
data.results.forEach(res => {
html.push(`<h1>${res.title}</h1>`);
html.push(`<p>${res.url}</p>`);
html.push(`<p>${res.abstract}</p>`);
html.push(`<p>${res.published_date}</p>`);
html.push(`<image>${res.multimedia[4]}</image>`);
})
document.getElementById("res").innerHTML = html.join("");
})
Run Code Online (Sandbox Code Playgroud)