JS筆記 14 JSON格式處理器

2021-09-24 08:15:20 字數 1567 閱讀 6445

json字串:

json處理器有兩個靜態方法:

json.stringify()

json還有第三個引數,也不常用到,感興趣的朋友可參考其他文件

console.log(json.stringify(123)); //'123'

console.log(json.stringify('123')); //'"123"'

console.log(json.stringify(true)); // 'true'

console.log(json.stringify('true')); //'"true"'

console.log(json.stringify(null)); //'null'

console.log(json.stringify()); //''

console.log(json.stringify()); //'' 物件中的undefined被瀏覽器過濾掉

console.log(json.stringify([1, ])); //'[1,]'

console.log(json.stringify([undefined, ])); //'[null,]' 陣列中的undefined轉為null

console.log(json.stringify(/^\d$/)); //{} 正則會轉為空物件

複製**

//json的第二個引數:指定可以轉換成json字串的屬性

let obj =

console.log(json.stringify(obj, ['name', 'id'])); //''

複製**

方法的第二個引數是函式的情況

function

fn() ;

console.log(json.stringify(, fn)); //'123'

function

fn1(key, value) ;

console.log(json.stringify(, fn1)); //

function

fn3(key, value) ;

console.log(json.stringify(, fn3)); //

複製**

console.log(json.parse('123')); //123

console.log(json.parse('"123"')); //"123"

console.log(json.parse('true')); //true

console.log(json.parse('null')); //null

console.log(json.parse('')); //

複製**

的第二個引數是函式的情況

function

f(key, value)

return value;

}console.log(json.parse('', f)); //

複製**

python高階寶典14 json 資料處理

先看 用 loads 讀取json,返回乙個python字典 import json stringjson json字串總是用雙引號 jsontopython json.loads stringjson print jsontopython dumps 輸出 json 格式 pythonvalue ...

第14章 預處理器

c預處理器在源 編譯之前對其進行一些文字性質的操作。它的主要任務包括刪除注釋 插入被 include指令包含的檔案的內容 定義和替換由 define指令定義的符號以及確定 的部分內容是否應該根據一些條件編譯指令進行編譯。在 define中,如果定義的內容很長,可以分成幾行,除了最後一行之外,每行的末...

C和指標14章 預處理器筆記

1.define define name stuff 當有name出現時,預處理器就會把它替換成stuff 當stuff非常長的時候,可以分成好幾行,除了最後一行外,每行都要加上乙個反斜槓 define debug print printf file s line d x d,y d,z d fil...