常見前端資料格式轉換

2021-10-01 09:35:04 字數 1057 閱讀 2472

開發的過程當中遇到這樣乙個處理資料的需求:

場景:

const todayilearn =

變成如下:

const todayilearn =

處理方案:

const todayilearn =

const mapobj =

;json

.parse

(json

.stringify

(todayilearn)

.replace

(/_id|created_at|updated_at/gi

, matched => mapobj[matched]

))

注意點:

(1)undefined、任意的函式以及symbol作為物件屬性值時 json.stringify() 將跳過(忽略)對它們進行序列化

例如:

const data =};

json

.stringify

(data)

;// 輸出:?

// ""

(2)undefined、任意的函式以及symbol作為陣列元素值時,json.stringify() 會將它們序列化為 null

例如:

json

.stringify([

"aaa"

, undefined,

functionaa(

),symbol

('dd')]

)// 輸出:?

// "["aaa",null,null,null]"

C 資料格式轉換

本文主要講述整數 二進位制字串與十六進製制字串之間的轉換。使用 ltoa s 函式可以將整數轉換為二進位制字串。該函式的作用是將乙個 long 整數轉換為字串。ltoa s 函式有很多格式,其中的乙個格式為 errno t ltoa s long value,char str,int radix 其...

Python資料格式轉換

函式 描述int x base 將x轉換為乙個整數 long x base 將x轉換為乙個長整數 float x 將x轉換到乙個浮點數 complex real imag 建立乙個複數 str x 將物件 x 轉換為字串 repr x 將物件 x 轉換為表示式字串 eval str 用來計算在字串中...

ArcGIS中常見資料格式及其轉換

一 arcgis自身的資料格式轉換 shp與個人及檔案地理資料庫之間的轉換 1 資料右鍵匯出,選擇.shp或對應的資料庫直接轉換 2 工具箱中 轉換工具 轉為shapefile批量或者轉出至地理資料庫批量 shp與e00格式轉換 工具箱中 轉換工具 轉為coverage 由e00匯入,然後cover...