как получить неформатируемый json

153
11 июня 2019, 22:40

файл:

{
  "participants": [
    {
      "name": "\u00d0\u0098\u00d0\u00bb\u00d1\u008c\u00d1\u008f \u00d0\u00a8\u00d0\u00be\u00d1\u0081\u00d1\u0082"
    },
    {
      "name": "\u00d0\u009a\u00d0\u00b8\u00d1\u0080\u00d0\u00b8\u00d0\u00bb\u00d0\u00bb \u00d0\u009a\u00d1\u0083\u00d1\u0088\u00d0\u00bd\u00d0\u00b8\u00d1\u0080"
    },
    {
      "name": "\u00d0\u009c\u00d0\u00b0\u00d0\u00ba\u00d1\u0081\u00d0\u00b8\u00d0\u00bc \u00d0\u009b\u00d1\u008e\u00d0\u00b1\u00d0\u00b8\u00d1\u0082\u00d0\u00b5\u00d0\u00bb\u00d0\u00b5\u00d0\u00b2"
    },
    {
      "name": "\u00d0\u009c\u00d0\u00b0\u00d0\u00ba\u00d1\u0081\u00d0\u00b8\u00d0\u00bc \u00d0\u009f\u00d1\u0083\u00d1\u0085"
    },
    {
      "name": "\u00d0\u0090\u00d0\u00bb\u00d0\u00b5\u00d0\u00ba\u00d1\u0081\u00d0\u00b5\u00d0\u00b9 \u00d0\u00a0\u00d0\u00b0\u00d0\u00bc\u00d0\u00b5\u00d0\u00bd\u00d1\u0081\u00d0\u00ba\u00d0\u00b8\u00d0\u00b9"
    },
    {
      "name": "\u00d0\u0094\u00d0\u00b0\u00d1\u0080\u00d1\u008c\u00d1\u008f \u00d0\u0098\u00d0\u00b2\u00d0\u00b0\u00d0\u00bd\u00d0\u00be\u00d0\u00b2\u00d0\u00b0"
    },
    {
      "name": "\u00d0\u0098\u00d0\u00b3\u00d0\u00be\u00d1\u0080\u00d1\u008c \u00d0\u0093\u00d0\u00bb\u00d0\u00b0\u00d0\u00b4\u00d0\u00ba\u00d0\u00b8\u00d1\u0085"
    },
    {
      "name": "Pavel  Geptner"
    },
    {
      "name": "\u00d0\u0090\u00d0\u00bd\u00d0\u00b4\u00d1\u0080\u00d0\u00b5\u00d0\u00b9 \u00d0\u00a1\u00d0\u00be\u00d0\u00bb\u00d0\u00be\u00d0\u00bc\u00d0\u00be\u00d0\u00bd\u00d0\u00be\u00d0\u00b2"
    }
  ],
  "messages": [
    {
      "sender_name": "\u00d0\u0090\u00d0\u00bb\u00d0\u00b5\u00d0\u00ba\u00d1\u0081\u00d0\u00b5\u00d0\u00b9 \u00d0\u00a0\u00d0\u00b0\u00d0\u00bc\u00d0\u00b5\u00d0\u00bd\u00d1\u0081\u00d0\u00ba\u00d0\u00b8\u00d0\u00b9",
      "timestamp_ms": 1543941856123,
      "content": "https://www.facebook.com/716628253/posts/10157110751043254/",
      "share": {
        "link": "https://www.facebook.com/shipachev/posts/10157110751043254"
      },
      "type": "Share"
    },
    {
      "sender_name": "\u00d0\u009c\u00d0\u00b0\u00d0\u00ba\u00d1\u0081\u00d0\u00b8\u00d0\u00bc \u00d0\u009b\u00d1\u008e\u00d0\u00b1\u00d0\u00b8\u00d1\u0082\u00d0\u00b5\u00d0\u00bb\u00d0\u00b5\u00d0\u00b2",
      "timestamp_ms": 1543822921939,
      "content": "\u00d0\u00b2\u00d1\u0081\u00d0\u00b5\u00d0\u00bc \u00d0\u00bf\u00d1\u0080\u00d0\u00b8\u00d0\u00b2\u00d0\u00b5\u00d1\u0082, \u00d1\u0080\u00d1\u008b\u00d0\u00bb\u00d1\u0081\u00d1\u008f \u00d0\u00b2 \u00d1\u0081\u00d0\u00b5\u00d1\u0082\u00d0\u00b8 \u00d0\u00b8 \u00d0\u00bd\u00d0\u00b0\u00d1\u0088\u00d0\u00b5\u00d0\u00bb \u00d0\u00b2\u00d0\u00ba\u00d1\u0083\u00d1\u0081\u00d0\u00bd\u00d0\u00be\u00d1\u0081\u00d1\u0082\u00d0\u00b8 \u00d0\u00b4\u00d0\u00bb\u00d1\u008f yii2, \u00d1\u0080\u00d0\u00b5\u00d0\u00b1\u00d1\u008f\u00d1\u0082\u00d0\u00b0 \u00d1\u0081\u00d1\u0082\u00d1\u0080\u00d1\u008f\u00d0\u00bf\u00d0\u00b0\u00d1\u008e\u00d1\u0082 \u00d0\u00bd\u00d1\u0083\u00d0\u00b6\u00d0\u00bd\u00d1\u008b\u00d0\u00b5 \u00d0\u00b2\u00d0\u00b8\u00d0\u00b4\u00d0\u00b6\u00d0\u00b8\u00d1\u0082\u00d1\u008b:\nhttps://www.2amigos.us/open-source?page=1&per-page=9",
      "share": {
        "link": "https://www.2amigos.us/open-source?page=1&per-page=9"
      },
      "type": "Share"
    }
  ],
  "title": "\u00d0\u0098\u00d0\u0097\u00d0\u0091\u00d0\u0090.tech",
  "is_still_participant": true,
  "thread_type": "RegularGroup",
  "thread_path": "archived_threads/IZBAtech_oV-Kxgzzjg"
}

`

выполняю

Json::decode(file_get_contents($this->getFolder() . $this->fileName($file)))

получаю

array(6) { ["participants"]=> array(9) { [0]=> array(1) { ["name"]=> string(33) "ÐлÑÑ Ð¨Ð¾ÑÑ" } [1]=> array(1) { ["name"]=> string(49) "ÐиÑилл ÐÑÑниÑ" } [2]=> array(1) { ["name"]=> string(61) "ÐакÑим ÐÑбиÑелев" } [3]=> array(1) { ["name"]=> string(37) "ÐакÑим ÐÑÑ" } [4]=> array(1) { ["name"]=> string(65) "ÐлекÑей РаменÑкий" } [5]=> array(1) { ["name"]=> string(49) "ÐаÑÑÑ Ðванова" } [6]=> array(1) { ["name"]=> string(49) "ÐгоÑÑ ÐладкиÑ" } [7]=> array(1) { ["name"]=> string(14) "Pavel Geptner" } [8]=> array(1) { ["name"]=> string(61) "ÐндÑей Соломонов" } } ["messages"]=> array(2) { [0]=> array(5) { ["sender_name"]=> string(65) "ÐлекÑей РаменÑкий" ["timestamp_ms"]=> int(1543941856123) ["content"]=> string(59) "https://www.facebook.com/716628253/posts/10157110751043254/" ["share"]=> array(1) { ["link"]=> string(58) "https://www.facebook.com/shipachev/posts/10157110751043254" } ["type"]=> string(5) "Share" } [1]=> array(5) { ["sender_name"]=> string(61) "ÐакÑим ÐÑбиÑелев" ["timestamp_ms"]=> int(1543822921939) ["content"]=> string(333) "вÑем пÑивеÑ, ÑÑлÑÑ Ð² ÑеÑи и наÑел вкÑÑноÑÑи Ð´Ð»Ñ yii2, ÑебÑÑа ÑÑÑÑпаÑÑ Ð½ÑжнÑе виджиÑÑ: https://www.2amigos.us/open-source?page=1&per-page=9" ["share"]=> array(1) { ["link"]=> string(52) "https://www.2amigos.us/open-source?page=1&per-page=9" } ["type"]=> string(5) "Share" } } ["title"]=> string(21) "ÐÐÐÐ.tech" ["is_still_participant"]=> bool(true) ["thread_type"]=> string(12) "RegularGroup" ["thread_path"]=> string(36) "archived_threads/IZBAtech_oV-Kxgzzjg" }

как мне получить вместо этого

["name"]=> string(33) "ÐлÑÑ Ð¨Ð¾ÑÑ"

это

["name"]=> string(33) "\u00d0\u0098\u00d0\u00bb\u00d1\u008c\u00d1\u008f \u00d0\u00a8\u00d0\u00be\u00d1\u0081\u00d1\u0082"
Answer 1
<?php
        //Enter your code here, enjoy!
$str = '{
  "participants": [
    {
      "name": "\u00d0\u0098\u00d0\u00bb\u00d1\u008c\u00d1\u008f \u00d0\u00a8\u00d0\u00be\u00d1\u0081\u00d1\u0082"
    },
    {
      "name": "\u00d0\u009a\u00d0\u00b8\u00d1\u0080\u00d0\u00b8\u00d0\u00bb\u00d0\u00bb \u00d0\u009a\u00d1\u0083\u00d1\u0088\u00d0\u00bd\u00d0\u00b8\u00d1\u0080"
    },
    {
      "name": "\u00d0\u009c\u00d0\u00b0\u00d0\u00ba\u00d1\u0081\u00d0\u00b8\u00d0\u00bc \u00d0\u009b\u00d1\u008e\u00d0\u00b1\u00d0\u00b8\u00d1\u0082\u00d0\u00b5\u00d0\u00bb\u00d0\u00b5\u00d0\u00b2"
    },
    {
      "name": "\u00d0\u009c\u00d0\u00b0\u00d0\u00ba\u00d1\u0081\u00d0\u00b8\u00d0\u00bc \u00d0\u009f\u00d1\u0083\u00d1\u0085"
    },
    {
      "name": "\u00d0\u0090\u00d0\u00bb\u00d0\u00b5\u00d0\u00ba\u00d1\u0081\u00d0\u00b5\u00d0\u00b9 \u00d0\u00a0\u00d0\u00b0\u00d0\u00bc\u00d0\u00b5\u00d0\u00bd\u00d1\u0081\u00d0\u00ba\u00d0\u00b8\u00d0\u00b9"
    },
    {
      "name": "\u00d0\u0094\u00d0\u00b0\u00d1\u0080\u00d1\u008c\u00d1\u008f \u00d0\u0098\u00d0\u00b2\u00d0\u00b0\u00d0\u00bd\u00d0\u00be\u00d0\u00b2\u00d0\u00b0"
    },
    {
      "name": "\u00d0\u0098\u00d0\u00b3\u00d0\u00be\u00d1\u0080\u00d1\u008c \u00d0\u0093\u00d0\u00bb\u00d0\u00b0\u00d0\u00b4\u00d0\u00ba\u00d0\u00b8\u00d1\u0085"
    },
    {
      "name": "\u00d0\u0090\u00d0\u00bd\u00d0\u00b4\u00d1\u0080\u00d0\u00b5\u00d0\u00b9 \u00d0\u00a1\u00d0\u00be\u00d0\u00bb\u00d0\u00be\u00d0\u00bc\u00d0\u00be\u00d0\u00bd\u00d0\u00be\u00d0\u00b2"
    }
  ],
  "messages": [
    {
      "sender_name": "\u00d0\u0090\u00d0\u00bb\u00d0\u00b5\u00d0\u00ba\u00d1\u0081\u00d0\u00b5\u00d0\u00b9 \u00d0\u00a0\u00d0\u00b0\u00d0\u00bc\u00d0\u00b5\u00d0\u00bd\u00d1\u0081\u00d0\u00ba\u00d0\u00b8\u00d0\u00b9",
      "timestamp_ms": 1543941856123,
      "content": "https://www.facebook.com/716628253/posts/10157110751043254/",
      "share": {
        "link": "https://www.facebook.com/shipachev/posts/10157110751043254"
      },
      "type": "Share"
    },
    {
      "sender_name": "\u00d0\u009c\u00d0\u00b0\u00d0\u00ba\u00d1\u0081\u00d0\u00b8\u00d0\u00bc \u00d0\u009b\u00d1\u008e\u00d0\u00b1\u00d0\u00b8\u00d1\u0082\u00d0\u00b5\u00d0\u00bb\u00d0\u00b5\u00d0\u00b2",
      "timestamp_ms": 1543822921939,
      "content": "\u00d0\u00b2\u00d1\u0081\u00d0\u00b5\u00d0\u00bc \u00d0\u00bf\u00d1\u0080\u00d0\u00b8\u00d0\u00b2\u00d0\u00b5\u00d1\u0082, \u00d1\u0080\u00d1\u008b\u00d0\u00bb\u00d1\u0081\u00d1\u008f \u00d0\u00b2 \u00d1\u0081\u00d0\u00b5\u00d1\u0082\u00d0\u00b8 \u00d0\u00b8 \u00d0\u00bd\u00d0\u00b0\u00d1\u0088\u00d0\u00b5\u00d0\u00bb \u00d0\u00b2\u00d0\u00ba\u00d1\u0083\u00d1\u0081\u00d0\u00bd\u00d0\u00be\u00d1\u0081\u00d1\u0082\u00d0\u00b8 \u00d0\u00b4\u00d0\u00bb\u00d1\u008f yii2, \u00d1\u0080\u00d0\u00b5\u00d0\u00b1\u00d1\u008f\u00d1\u0082\u00d0\u00b0 \u00d1\u0081\u00d1\u0082\u00d1\u0080\u00d1\u008f\u00d0\u00bf\u00d0\u00b0\u00d1\u008e\u00d1\u0082 \u00d0\u00bd\u00d1\u0083\u00d0\u00b6\u00d0\u00bd\u00d1\u008b\u00d0\u00b5 \u00d0\u00b2\u00d0\u00b8\u00d0\u00b4\u00d0\u00b6\u00d0\u00b8\u00d1\u0082\u00d1\u008b:\nhttps://www.2amigos.us/open-source?page=1&per-page=9",
      "share": {
        "link": "https://www.2amigos.us/open-source?page=1&per-page=9"
      },
      "type": "Share"
    }
  ],
  "title": "\u00d0\u0098\u00d0\u0097\u00d0\u0091\u00d0\u0090",
  "is_still_participant": true,
  "thread_type": "RegularGroup",
  "thread_path": "archived_threads"
}';
$json = changeCharset(json_decode($str, TRUE));
function changeCharset( $array ){
    array_walk_recursive( $array, function(&$item) { 
       $item = iconv("UTF-8", "ISO-8859-1", $item); 
    });
    return $array;
}

Результат:

array(6) {
  ["participants"]=>
  array(8) {
    [0]=>
    array(1) {
      ["name"]=>
      string(17) "Вася Центр"
    }
    [1]=>
    array(1) {
      ["name"]=>
      string(25) "Артем Лор"
    }
    [2]=>
    array(1) {
      ["name"]=>
      string(31) "Дима Ковалчук"
    }
    [3]=>
    array(1) {
      ["name"]=>
      string(19) "Гена Конь"
    }
    [4]=>
    array(1) {
      ["name"]=>
      string(33) "Рая Гермовна"
    }
    [5]=>
    array(1) {
      ["name"]=>
      string(25) "Паша Ветер"
    }
    [6]=>
    array(1) {
      ["name"]=>
      string(25) "Кот"
    }
    [7]=>
    array(1) {
      ["name"]=>
      string(31) "Гоша Купер"
    }
  }
  ["messages"]=>
  array(2) {
    [0]=>
    array(5) {
      ["sender_name"]=>
      string(33) "Гоша Купер"
      ["timestamp_ms"]=>
      string(13) "1543941856123"
      ["content"]=>
      string(59) "https://www.facebook.com/716628253/posts/10157110751043254/"
      ["share"]=>
      array(1) {
        ["link"]=>
        string(58) "https://www.facebook.com/shipachev/posts/10157110751043254"
      }
      ["type"]=>
      string(5) "Share"
    }
    [1]=>
    array(5) {
      ["sender_name"]=>
      string(31) "Паша Ветер"
      ["timestamp_ms"]=>
      string(13) "1543822921939"
      ["content"]=>
      string(203) "всем привет, рылся в сети и нашел вкусности для yii2, ребята стряпают нужные виджиты:
https://www.2amigos.us/open-source?page=1&per-page=9"
      ["share"]=>
      array(1) {
        ["link"]=>
        string(52) "https://www.2amigos.us/open-source?page=1&per-page=9"
      }
      ["type"]=>
      string(5) "Share"
    }
  }
  ["title"]=>
  string(13) "tech"
  ["is_still_participant"]=>
  string(1) "1"
  ["thread_type"]=>
  string(12) "RegularGroup"
  ["thread_path"]=>
  string(16) "archived_threads"
}

Теперь находите нужное Вам значение и меняйте его. Online решение

READ ALSO
Как использовать класс в CLI

Как использовать класс в CLI

Есть такой вопросКак запускать класс из cli

169
Ajax обновление

Ajax обновление

В общем имеется страница с блоками в каждом фото, описание и кнопка с таймеромДанные загружаются из базы по циклу while

100
ZF3: Как в Zend Framefork-е зарегистрировать Doctrine Type?

ZF3: Как в Zend Framefork-е зарегистрировать Doctrine Type?

Как известно Doctrine не понимает тип enum MySQLПри генерации сущностей выходит ошибка:

104