简体   繁体   English

JSON语法混乱

[英]JSON syntax confusion

I am working with an api where I am retrieving JSON data. 我正在使用API​​检索JSON数据。 I've come across a data type that I am unfamiliar with and I would like some insight into what it means. 我遇到了一种我不熟悉的数据类型,我想对它的含义有所了解。

An example is shown below. 一个例子如下所示。

{     
   "data":{  
      "id":"92",
      "name":"harry",
      "friends":"a:2:{i:0;s:1:\"1\";i:1;s:2:\"15\";}"
      "enemies":"a:0:{}"
    },
   "error":false
}

I am unsure how to interpret the "friends" and "enemies" fields. 我不确定如何解释“朋友”和“敌人”领域。 I am aware that arrays are represented by [ ] and objects by { }. 我知道数组由[]表示,对​​象由{}表示。

Could anyone explain what they mean? 谁能解释他们的意思?

Thank you. 谢谢。

The fields contain arrays that have been serialized by PHP. 这些字段包含已由PHP序列化的数组。

For example 例如

<?php
  $friends = "a:2:{i:0;s:1:\"1\";i:1;s:2:\"15\";}";
  $arr = unserialize($friends);
  var_dump($arr);
?>

gives

array(2) { 
    [0]=> string(1) "1" 
    [1]=> string(2) "15"
} 

What these values represent will be application-specific. 这些值代表的是特定于应用程序的。

The value of friends is a string with the value: a:2:{i:0;s:1:"1";i:1;s:2:"15";} friends的值是一个字符串,其值如下:a:2:{i:0; s:1:“ 1”; i:1; s:2:“ 15”;}

What this string represents depends on what the application does with it 该字符串表示什么取决于应用程序对其进行的处理

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

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