> For the complete documentation index, see [llms.txt](https://tobyisme.gitbook.io/php/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tobyisme.gitbook.io/php/coding-problem.md).

# Coding problem

### *製作API所會碰到的問題*

## JSON 中文亂碼

在PHP中要將資料轉換成JSON格式只需要用json\_encode這個函示就可以搞定。

```php
$jude = array('a'=>'小志仔');
echo json_encode($jude);
```

PHP中若是有中文做json\_encode會變成亂碼，所以必須要在encode之前先把中文變成亂碼，然後encode完以後再把中文變回來。

```php
$jude = urlencode(array('a'=>'小志仔'));
echo urldecode(json_encode($jude));
```
