[英]how to remove “result”: “success” on json callback
The result of the call to the api server is a json file, which begins with this string: 调用api服务器的结果是一个json文件,它以这个字符串开头:
{
"result": "success"
, "data": {"total":16080,"pageCount":161,"result":[{"packWidth":250,"itemNo"
How do I remove the part that I do not care? 如何删除我不关心的部分? that is, this
就是这个
{
"result": "success"
, "data": {"total":16080,"pageCount":161,"result":
The complete result is: 完整的结果是:
{
"result": "success"
, "data": {"total":16080,"pageCount":161,"result": [{"packWidth":250,"itemNo":"1203945","groupItemNo":"1203945","status":1,"categoryId":105096,"packType":"Color Box","barcode":"6922833439687","modelLabel":"Color","packQty":24,"packInclude":"USB Cable, User Manual, USB Charger, Earphone, 1pcs Li-Battery, LCD Protector, Leather Case, Plastic Case","clearance":false,"id":103928,"packWeight":"12.500","price":"181.2800","packLength":400,"description":"description test","unitWeight":"0.726","packHeight":300}]}}
I use the PHP language 我使用PHP语言
I have to remove the initial part: 我必须删除最初的部分:
{
"result": "success"
, "data": {"total":16080,"pageCount":161,"result":
and the final: 和决赛:
}}
If you want to use part of a JSON to populate a CSV file, then parse the json using json_decode
method and access the necessary information. 如果要使用JSON的一部分来填充CSV文件,则使用
json_decode
方法解析json并访问必要的信息。
Try something like this: 尝试这样的事情:
var jsonObject = json_decode(myJson);
var interestingPart = jsonObject.data.result;
You can now access the data in an Object manner. 您现在可以以对象方式访问数据。 Or if you want to get a json back from it, then use:
或者如果你想从中获取一个json,那么使用:
var interestingJson = json_encode(interestingPart);
Not tested, but it should work 没有经过测试,但应该可行
preg_replace("/^.*?:(?=\w*\[) | (\w*}\w*}\w*$)/", "", $str);
Edit: i wrote this before I knew of json_decode, you should really use the json functions like suggested in fazovskys answer. 编辑:我在知道json_decode之前写过这个,你应该真的使用像fazovskys回答中建议的json函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.