PHP数组从JSON网址 [英] php array in url from json

查看:142
本文介绍了PHP数组从JSON网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想做的事:

我有一些JSON像这样

I have some json like this

  var foo = {
   format:"json",
   type:"test",
   id:"26443"
  };

和我awant投入,在这样的网址

and I awant to put that in a url like this

 'http://example.com/a:3:{s:6:"format";s:4:"json";s:4:"type";s:4:"test";s:2:"id";s:5:"26443";}'

我会再投入ajax调用但一切我都试过在错误导致501错误的URI可能有人告诉我如何做到这一点。

which I will then put into ajax call but everything I have tried results in error 501 BAD URI could someone tell me how to do this

我已经试过这
修改

再寻找并提醒这一功能,是构建结果correcty他们只是arrn't使用propler或者通过AJAX或浏览器

after looking again and alerting the results of this function it IS build the results correcty they just arrn't being used propler either by ajax or the browser

 function js_array_to_php_array(a) {
  var a_php = "";
  var total = 3;

  for (var key in a){
   total;
   a_php = a_php + "s:" + String(key).length  + ":\""  + String(key) + "\";s:" + String(a[key]).length  +  ":\"" + String(a[key])  + "\";";
  }
  a_php = "a:" + total +":{" + a_php + "}";
  return a_php;
 }

当我使用HTTP狐狸它得到这回

when I use http fox it get this back

 http://example.com/a:3:%7Bs:6:%22format%22;s:4:%22json%22;s:4:%22type%22;s:4:%test%22;s:2:%22id%22;s:5:%2226443%22;}

我觉得奇怪,因为它E codeS的一切,但最后花括号

which i find odd because it ecodes everything but the last curly bracket

推荐答案

所以事实证明没有什么不对的功能js_array_to_php_array它确实做到了,因为我需要它的问题是,我需要使用JSONP而不是JSON运行我的Ajax调用的时候,因为我要去跨域这也解释了为什么code在URL中工作,但不是当我跑AJAX

so as it turns out there is nothing wrong with the function js_array_to_php_array it did exactly as I needed it to the problem was that I needed to use JSONP instead of JSON when running my ajax call as I was going cross domain which also explains why the code worked in the url but not when I ran ajax

感谢大家的帮助。

这篇关于PHP数组从JSON网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆