PHPスクリプトを使用してCSVからjsonに変換する顧客データがあります。
変換されると、データは次のようにすべてごちゃ混ぜになります。
[{"顧客番号":"12345","顧客名":"顧客 1","住所コード":"プライマリ","販売員 ID":"aa","配送先住所 1":"12345", "Ship to Address 2":"123, fake street","Ship to Address 3":"","Ship to City":"Toronto","Ship to Province":"ONTARIO","Ship to Postal Code" :"A1A 1A1","国コード":"CA","配送先の国":"カナダ","配送先の担当者":"John Doe","配送先の電話番号":"416-555-5555" ,"Ship to Fax":"416-555-5552","Shipping Method":"OUR TRUCK","Bill to Address 1":"12345","Bill to Address 2":"123、fake street","Bill to Address 3":"","Bill to City":"Toronto","Bill to Province":"ONTARIO","Bill to Postal Code":"A1A 1A1","Bill to Phone":"416-555-5555","Tax Schedule ID":"HST ON/S","Location Code":"TOR","Payment Terms ID":"30 DAYS PD CHEQUE","Credit Limit Amount":"2,000.00","Comment1":"30D PDC /10/11-NSF=WR BK ACCT","Comment2":"","Hold":"1","Price List":"EASTGEN"} ]Bill to Phone":"416-555-5555","Tax Schedule ID":"HST ON/S","Location Code":"TOR","Payment Terms ID":"30 DAYS PD CHEQUE","Credit限度額":"2,000.00","コメント1":"30D PDC /10/11-NSF=WR BK ACCT","コメント2":"","保留":"1","価格表":"EASTGEN" }]Bill to Phone":"416-555-5555","Tax Schedule ID":"HST ON/S","Location Code":"TOR","Payment Terms ID":"30 DAYS PD CHEQUE","Credit限度額":"2,000.00","コメント1":"30D PDC /10/11-NSF=WR BK ACCT","コメント2":"","保留":"1","価格表":"EASTGEN" }]
.
次に、str_replace を使用して出力を整理し、見栄えを良くします。ここに私が持っているものがあります:
$newArray = str_replace(":",": ",json_encode($newArray));
$newArray = str_replace("[","[\n",$newArray);
$newArray = str_replace("{","{\n",$newArray);
$newArray = str_replace(",",",\n",$newArray);
$newArray = str_replace("},","\n},",$newArray);
$newArray = nl2br($newArray);
.
私が抱えている問題は、出力が次のように表示されることです。
[
{
"お客様番号": "12345",
"顧客名": "顧客 1",
"住所コード": "一次",
"販売員ID": "aa",
"配送先住所1": "12345",
"配送先住所 2": "123,
フェイクストリート」、
"配送先住所 3": "",
"配送先都市": "トロント",
"都道府県": "ONTARIO",
"配送先の郵便番号": "A1A 1A1",
"国コード": "CA",
"配送先の国": "カナダ",
"Ship to Contact Person": "John Doe",
"Ship to Phone": "416-555-5555",
"Ship to Fax": "416-555-5552",
"配送方法": "OUR TRUCK",
"請求先住所 1": "12345",
"請求先住所 2": "123,
フェイクストリート」、
"請求先住所 3": "",
"請求先市": "トロント",
"州への請求書": "ONTARIO",
"請求先郵便番号": "A1A 1A1",
"請求先電話番号": "416-555-5555",
"納税スケジュールID": "HST ON/S",
"ロケーションコード": "TOR",
"支払条件 ID": "30 DAYS PD CHEQUE",
"与信限度額": "2,
000.00",
"コメント1": "30D PDC /10/11-NSF=WR BK ACCT",
"コメント2": "",
"ホールド": "1",
"価格表": "EASTGEN"}]
Ship to Address 2 、 Bill to Address 2 、および Credit Limit Amount に注意してください。私のstr_replaceのために、そこに改行が追加されました。問題は、jsonを読み取るために使用するアプリが、正しく登録するために同じ行にそれを必要とすることです。アドレスまたは別の変数の一部でない限り、カンマを改行に置き換える方法はありますか?