简体   繁体   English

WP REST API-响应中的奇怪格式

[英]WP REST API - Strange formatting in response

So I'm working with the wp rest api and the wp rest controller plugin. 因此,我正在使用wp rest api和wp rest控制器插件。 I have a music theme that's doing some interesting things. 我有一个音乐主题正在做一些有趣的事情。 When i make the API call one of the properties i get is this: 当我进行API调用时,得到的属性之一是:

"subheader_img": [
    "a:1:{i:0;a:5:{s:5:\"image\";s:0:\"\";s:5:\"color\";s:0:\"\";s:6:\"repeat\";s:6:\"repeat\";s:8:\"position\";s:8:\"left top\";s:11:\"attachement\";s:6:\"scroll\";}}"
  ],

its a string, that i know should be an array. 它是一个字符串,我知道应该是一个数组。 I'm not sure what type encoding is applied to it. 我不确定对其应用哪种类型的编码。 But i'm trying to clean it up on the javascript side. 但我正在尝试在JavaScript方面进行清理。 Does anyone know what's being done to this array turned string? 有谁知道对这个数组转换后的字符串做了什么? And if there are any javascript functions that can help? 并且,如果有任何JavaScript函数可以提供帮助? I've tried JSON.Parse and that obviously won't work because... its not JSON. 我已经尝试过JSON.Parse,但显然不起作用,因为...它不是JSON。 I've also tried stripping away the first few characters string.substring(x), but i run into the same problem after that. 我也尝试剥离掉头几个字符string.substring(x),但是在那之后我遇到了同样的问题。

i know its something simple, i'm just not sure what. 我知道它很简单,但我不确定。

If its possible I'd like to parse it in javascript, modifying the endpoint might be more difficult because of the wordpress theme. 如果可能的话,我想用javascript解析它,由于wordpress主题,修改端点可能会更加困难。

Use WP's functions for serialization: 使用WP的函数进行序列化:

The gist: Check if your array item is a serialized string ( is_serialized_string ), and then maybe_unserialize it. 要点:检查您的数组项是否为序列化的字符串( is_serialized_string ),然后maybe_unserialize对其进行序列化。 Then you can evaluate the result to see if it's in a format you're expecting (such as an array). 然后,您可以评估结果以查看其格式是否符合您的期望(例如数组)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM