javascript - Json_encode 变音符号输出

标签 javascript php json wordpress jsonp

我想用德语元音变音显示我的输出,我得到了这样的输出,例如 Fu009\但我需要这样的“fü”。

<?php
$json = (object) array(
    "salutation" = > ''.$order - > order_custom_fields['_billing_anrede'][0].
    '',
    "title" = > ''.$order - > order_custom_fields['_billing_titel'][0].
    '',
    "first_name" = > ''.$order - > order_custom_fields['_billing_first_name'][0].
    '',
    "last_name" = > ''.$order - > order_custom_fields['_billing_last_name'][0].
    '',
    "street" = > ''.$order - > order_custom_fields['_billing_address_1'][0].
    '',
    "street_number" = > ''.$order - > order_custom_fields['_billing_address_2'][0].
    '',
    "address_supplement" = > ''.$order - > order_custom_fields['_billing_company'][0].
    '',
    "zipcode" = > ''.$order - > order_custom_fields['_billing_postcode'][0].
    '',
    "city" = > ''.$order - > order_custom_fields['_billing_city'][0].
    '',
    "country" = > ''.$pais.
    '',
    "terms_accepted" = > true,
    "receiving_mails_accepted" = > ''.$email.
    '',
    "email" = > ''.$order - > order_custom_fields['_billing_email'][0].
    '',
    "lottery_accepted" = > false,
    "lottery_solution" = > "LOTTERY",
    "original_created_at" = > ''.date('Y-m-d\TH:i:sP', strtotime($order - > order_date)).
    '',


);

foreach($items as $item) {
    $sku = $wpdb - > get_var($wpdb - > prepare('SELECT meta_value FROM dsr_postmeta WHERE meta_key="_sku" AND post_id='.$item['product_id'].
        ''));
    $sku_s = explode('-', $sku);
    $camp = $sku_s[0];
    $itm_n = $sku_s[1];
    $json - > items[] = (object) array(
        "campaign_number" = > (int) $camp,
        "item_number" = > (int) $itm_n,

    );
}



array_push($json_full, $json);
echo json_encode($json_full);
?>

我正在考虑 htmlentities,或者 utf8 感谢您的帮助!!

最佳答案

如果您使用的是 PHP 5.4+,请将 echo json_encode($json_full); 更改为 echo json_encode($json_full, JSON_UNESCAPED_UNICODE);

可以在那里找到 json_encode 预定义常量的完整列表:http://lt1.php.net/manual/en/json.constants.php

演示

代码:

<?php
$json = (object) array(
  "uml" => "fü",
);

echo json_encode($json, JSON_UNESCAPED_UNICODE) . PHP_EOL;

echo json_encode($json) . PHP_EOL;

输出:

{"uml":"fü"}
{"uml":"f\u00fc"}

关于javascript - Json_encode 变音符号输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21550633/

相关文章:

javascript - Mocha 作用域函数未定义

php - E/ Volley : [1376] BasicNetwork. 执行请求 : Unexpected response code 404 for http://192. 168.0.109/connectphp/GetRestaurantData.php?restype=cafe

Ios Swift 解码从 GCM 通知发送的 json 数据

javascript - 地理图表上关闭工具提示按钮的工作版本代码?

javascript - 使用 lodash 获取 json 对象数组名称(元数据)

javascript - firefox javascript 在 href 中返回 false 重定向浏览器并显示 false

php - 无法打开流 : HTTP wrapper does not support writeable connections in Wp-Content(0755)

php - 将外部网页加载到我的页面而不重定向到不同的 URL

python - 在 JSON 输出中,强制每个左花括号出现在一个新的单独行中

json - GWT 客户端 JSON 解析很慢 - 如何改进?