我正试图从Google的Shopping API中提取数据.我能够成功下载数据,但是我在使用PHP解析它时遇到了麻烦.我还在学习,但我似乎遇到了多维数组的问题.我用它捕获JSON $json = json_decode($data);.
以下只是回显外部数组,但我不能从内部数组中拉出来:
foreach($json as $key => $value) {
echo $key . " : " . $value;
}
Run Code Online (Sandbox Code Playgroud)
如果我想获取每种产品的"标题","描述","品牌"和"可用性",我将如何解析它?
{
"kind": "shopping#products",
"etag": "\"T9uPnY2MZMB71TDpKXXZdr3yWX4/qtJ5vmpftFWNfijyLD9ti2Xpj-w\"",
"id": "tag:google.com,2010:shopping/products",
"selfLink": "https://www.googleapis.com/shopping/search/v1/public/products?country\u003dus&q\u003dsony&maxResults\u003d3&startIndex\u003d2",
"nextLink": "https://www.googleapis.com/shopping/search/v1/public/products?country\u003dus&q\u003dsony&maxResults\u003d3&startIndex\u003d5",
"previousLink": "https://www.googleapis.com/shopping/search/v1/public/products?country\u003dus&q\u003dsony&maxResults\u003d3&startIndex\u003d1",
"totalItems": 633694,
"startIndex": 2,
"itemsPerPage": 3,
"currentItemCount": 3,
"items": [
{
"kind": "shopping#product",
"id": "tag:google.com,2010:shopping/products/1161353/11882813508247586172",
"selfLink": "https://www.googleapis.com/shopping/search/v1/public/products/1161353/gid/11882813508247586172",
"product": {
"googleId": "11882813508247586172",
"author": {
"name": "Buy.com",
"accountId": "1161353"
},
"creationTime": "2011-04-24T05:13:38.000Z",
"modificationTime": "2011-08-05T17:45:24.000Z",
"country": "US",
"language": "en",
"title": "Sony BRAVIA KDL-46EX720 46 inch 3D LED …Run Code Online (Sandbox Code Playgroud) 我使用远程服务器来处理我想在Heroku上运行的应用程序上使用的beanstalkd队列.有没有办法运行Supervisor来监视队列命令(Laravel :) php artisan queue:listen正在运行?
每次客户输入数量时,我都会尝试显示小计.但是,当我循环输入时,我得到一个NaN总数.我相信它可能是我subtotal在我的脚本中声明变量的方式,但我之前没有遇到过这个:
$('.item-qty input').bind('keyup', function(){
var subtotal = 0.0;
$('.item-qty input').each(function(){
var class = $(this).attr('id');
var qty = $(this).val();
var price = $('.'+class).html();
price = parseFloat(price);
qty = parseInt(qty);
subtotal = subtotal + (price * qty);
});
$('.subtotal input').val(subtotal);
});
Run Code Online (Sandbox Code Playgroud) 我在创建schema.json文件时遇到问题,该文件可以使用babel-relay-plugin进行解析,而不会遇到错误.看一下relay的example文件夹中包含的schema.json文件,我尝试在GraphiQL中复制查询,但我似乎无法正确使用它.我正在使用Laravel作为后端.这是我可以通过GraphiQL完成的事情,还是向GraphQL端点发送请求并保存响应?
尝试解析schema.json文件时发生错误:
Cannot read property 'reduce' of undefined while parsing file: /Users/username/Sites/Homestead/Code/ineedmg-graphql/resources/assets/js/app.js
Run Code Online (Sandbox Code Playgroud)
最后一次尝试使用GraphiQL:
{
__schema {
queryType {
name
},
types {
kind,
name,
description,
fields {
name,
description,
type {
name,
kind,
ofType {
name
description
}
}
isDeprecated,
deprecationReason,
},
inputFields {
name
description
}
interfaces {
kind
name
description
},
enumValues {
name
description
isDeprecated
deprecationReason
}
},
mutationType {
name
},
directives {
name,
description,
onOperation,
onFragment,
onField,
args {
name
description …Run Code Online (Sandbox Code Playgroud) 我试图在我的数据库中插入~20K记录时遇到了问题.我注意到即使我在foreach循环中回显,我也没有在命令行中输出任何内容.相反,我插入~9440有关...的记录后出错
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 91 bytes) in /Users/me/Sites/Laravel/database/connection.php on line 293
这是我的代码(尝试使用Eloquent和Fluent):
<?php
class Process_Controller extends Base_Controller
{
public function action_migrate()
{
$properties = DB::table('raw_properties')->get('id');
$total = count($properties);
foreach ($properties as $x => $p) {
$r = RawProperty::find($p->id);
$count = $x + 1;
$prop_details = array(
'column' => $r->field,
// Total of 21 fields
);
DB::table('properties')->insert($prop_details);
echo "Created #$count of $total\n";
}
}
}
Run Code Online (Sandbox Code Playgroud) 我在尝试使用 Fedex 的 Web 服务提取跟踪信息时遇到问题。我正在使用有效的跟踪号码,并且可以在 Fedex 的网站上查看详细信息。但是,我收到错误 9040“我们的系统尚未收到以下货件的信息。请重试或致电 1.800.Go.FedEx(R) 800.463.3339 联系客户服务。” 我会遗漏一些东西吗?
我的代码:
<?php
$path_to_wsdl = "URL_TO_WSDL";
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1));
$request['WebAuthenticationDetail'] = array(
'UserCredential' =>array(
'Key' => 'MY_KEY',
'Password' => 'MY_PASSWORD'
)
);
$request['ClientDetail'] = array(
'AccountNumber' => 'MY_ACCT',
'MeterNumber' => 'MY_METER'
);
$request['TransactionDetail'] = array('CustomerTransactionId' => 'ActiveShipping');
$request['Version'] = array(
'ServiceId' => 'trck',
'Major' => '5',
'Intermediate' => '0',
'Minor' => '0'
);
$request['PackageIdentifier'] = array(
'Value' => 'TRACKING#',
'Type' => 'TRACKING_NUMBER_OR_DOORTAG');
$response …Run Code Online (Sandbox Code Playgroud) 我正在设置一个通用的React应用程序,并以此项目为基础.我成功地将请求(使用http-proxy)代理到我的Laravel后端.但是,我是Nodejs的新手,我不知道如何将JWT从代理服务器安全地存储到客户端.
我最初的想法是将令牌存储到localStorage,但问题是快递服务器将无法访问它.所以我的下一个猜测是将它存储为cookie,但我不确定如何将其存储在客户端上或将其作为所有传出请求的标头包含(另外,我可能需要某种csrf中间件).
那么我如何操纵我的api服务器的响应将令牌放入客户端中设置的cookie中,然后将其用作所有api请求的承载令牌?
// server.js
const targetUrl = 'http://' + config.apiHost + ':' + config.apiPort;
const app = new Express();
const server = new http.Server(app);
const proxy = httpProxy.createProxyServer({
target: targetUrl,
changeOrigin: true
});
// Proxy to Auth endpoint
app.use('/auth', (req, res) => {
// on a successful login, i want to store the token as a cookie
proxy.web(req, res, {target: targetUrl});
});
// Proxy to api endpoint
app.use('/api', (req, res) => {
// …Run Code Online (Sandbox Code Playgroud) 目前,表单中有复选框,并且在提交表单时,所选复选框的值存储在DB中.
<td><input type="Checkbox" name="valueList" value="Some value, with comma" >Some value, with comma</td>
<td><input type="Checkbox" name="valueList" value="Another Value, with comma" >Another value, with comma</td>
<td><input type="Checkbox" name="valueList" value="Yet another value" >Yet another value</td>
Run Code Online (Sandbox Code Playgroud)
但是,问题在于逗号,因为当前逻辑使用列表来存储这些值.因此Some value, with comma插入为Some value和with comma.使用以下内容创建当前列表:
<cfif isDefined("valueList")>
<cfset a=listlen(valueList)>
Run Code Online (Sandbox Code Playgroud)
然后代码继续循环遍历列表.这是valueList我在代码中找到的唯一引用.有没有办法将此转换为数组而不会使逗号成为问题?
我被要求处理由另一个程序员设置的网站的安全问题.到目前为止,我还没有看到任何代码,所以我在这一点上做了假设,我想覆盖我的基础.托管该站点的组进行了安全检查,发现他们的代码容易受到SQL注入攻击.
示例:www.example.com/code.php?pid = 2&ID = 35(GET参数ID易受SQL注入攻击)
现在,因为我是一个新手,我解释说,我可能可以解决与主机的问题,但他们的网站上仍然需要由人谁拥有安全的更深层次的知识看了过来.
因此,为了处理潜在的SQL注入(并且没有看到代码),我会使用mysql_real_escape_string:
$query = sprintf("SELECT * FROM table WHERE pid='%s' AND ID='%s'",
mysql_real_escape_string($pid),
mysql_real_escape_string($id));
Run Code Online (Sandbox Code Playgroud)
另外,我会考虑mysqli_real_escape_string和预处理语句,但我不知道它们是如何配置的.但mysql_real_escape_string会处理潜在的SQL注入吗?
我有一个表填充了不正确的数据,所以我需要切换一些数字.我不确定这是否是最好的方法,但我正在考虑使用具有多个IF条件的UPDATE语句.就像是:
UPDATE
`orders`
SET
`orderPriority` = 1
IF(`orderPriority` = 2)
OR
`orderPriority` = 2
IF(`orderPriority = 3)
OR
`orderPriority` = 3
IF(`orderPriority` = 1);
Run Code Online (Sandbox Code Playgroud)
显然这不起作用,但我的SQL技能缺乏.任何帮助表示赞赏!
所以我安装了Docker for Mac,我想使用VMWare Fusion而不是VirtualBox.进行搜索,我遇到了https://docs.docker.com/machine/drivers/vm-fusion/使用docker-machine.不确定这是否是我正在寻找的但是当Docker应用程序启动时我可以看到VMWare Fusion机器被暂停.是否需要额外的设置才能让新容器运行VMWare Fusion而不是VirtualBox?
看起来这应该是容易的部分,但我似乎无法实现这一目标.我created和updated字段没有填充.我已经尝试将字段重命名为不同的字段,但没有去.除了架构和设置类(非常基本),如下所示,我错过了什么?
Codeigniter v2.1.2 Datamapper ORM v1.8.2.1
架构:
CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`created` datetime NOT NULL,
`updated` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1
Run Code Online (Sandbox Code Playgroud)
用户类:
<?php
class User extends DataMapper
{
function User()
{
parent::DataMapper();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在处理或检修一个非常大的 React 应用程序。我有一个在 React 中处理的表单(并与 webpack 捆绑在一起)。成功提交表单后,我需要刷新页面上的数据表(不由 React/Webpack 处理)。我试图只在页面上注册一个侦听器并通过 jQuery 在 React 中触发该事件,但该事件未向侦听器注册。我做错了什么吗?
在 webpack 插件中(不使用开发服务器):
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}),
Run Code Online (Sandbox Code Playgroud)
在我的 React 代码中:
handleCreated = () => {
$(document).trigger('reload:datatable');
// ...
}
Run Code Online (Sandbox Code Playgroud)
在页面上(在脚本标签中):
$(document).on('reload:datatable', function (e) {
console.log('reload.task.table'); // This never gets called
});
Run Code Online (Sandbox Code Playgroud) php ×5
javascript ×3
arrays ×2
jquery ×2
mysql ×2
reactjs ×2
beanstalkd ×1
boot2docker ×1
codeigniter ×1
coldfusion ×1
cookies ×1
docker ×1
express ×1
fedex ×1
graphql ×1
graphql-js ×1
heroku ×1
if-statement ×1
json ×1
laravel ×1
macos ×1
memory-limit ×1
node.js ×1
parsing ×1
proxy ×1
relayjs ×1
security ×1
soap ×1
supervisord ×1
vmware ×1
webpack ×1