{
"status":{
"code":"1",
"message":"Get domain id success.",
"created_at":"2010-09-14 17:56:33"
},
"domains":{
"id":"444829",
"domain":"sexdiy.org",
"user_id":"9536"比如说这样的?我怎么提取到user_id的值9536呢?

解决方案 »

  1.   

    json_decode(json)
    返回一个php相对应的数组。
    但是注意对汉字不支持。
      

  2.   

    我是这样做的
    $a = json_decode($data);
    echo $a[0][1];
    不过我输出某个数组元素时,却只有一个符号 {
      

  3.   

    针对json  url base64等编码PHP都有相关编码函数解决的,谷歌就可以出来了。
    json_encode
    json_decode
    urlencode
    urldecode
    而且你会发现都是encode封装,decode解除封装
      

  4.   

    json decode为array  [{}] 
      

  5.   

    用这个试试<?php
    /**
     * json 生成,分析 支持中文
     */
    class Json_Helper {
    /**
     * 生成json
     */
    public static function encode($str){
    $json = json_encode($str);
    //linux
            return preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '\\1'))", $json);
            //windows
            //return preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2LE', 'UTF-8', pack('H4', '\\1'))", $json);
    } /**
     * 分析json
     */
    public static function decode($str) {
            return json_decode($str);
    }
    }
    ?>原文地址链接 http://www.stylejar.com/archives/php_json_encode_chinese.html
      

  6.   

    $ss = '{"status":{
    "code":"1",
    "message":"Get domain id success.",
    "created_at":"2010-09-14 17:56:33"
    },
    "domains":{
    "id":"444829",
    "domain":"sexdiy.org",
    "user_id":"9536"
    }}';
    $arr = json_decode($ss, true);
    echo $arr['domains']['user_id'];
    看一下json_decode的定义就知道啦:
    mixed json_decode ( string $json [, bool $assoc ] )
    接受一个 JSON 格式的字符串并且把它转换为 PHP 变量 参数json 
    待解码的 json string 格式的字符串。 assoc 
    当该参数为 TRUE 时,将返回 array 而非 object 。 
      

  7.   

    [{}]可以循环 根据索引 取值!!!  json_decode()看下手册