當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript json.parse函數代碼示例

本文整理匯總了TypeScript中vs/base/common/json.parse函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript parse函數的具體用法?TypeScript parse怎麽用?TypeScript parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了parse函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: readFile

				readFile(launchConfig, (err, contents) => {
					if (err) {
						return resolve([]);
					}

					const errors: ParseError[] = [];
					const json = parse(contents.toString(), errors);
					if (errors.length) {
						console.log(`Unable to parse ${launchConfig}`);
						return resolve([]);
					}

					if (json['configurations']) {
						for (const each of json['configurations']) {
							const type = each['type'];
							if (type) {
								if (launchConfigs.has(type)) {
									launchConfigs.set(type, launchConfigs.get(type)! + 1);
								} else {
									launchConfigs.set(type, 1);
								}
							}
						}
					}

					return resolve(asSortedItems(launchConfigs));
				});
開發者ID:VishalMadhvani,項目名稱:vscode,代碼行數:27,代碼來源:stats.ts

示例2: assertInvalidParse

function assertInvalidParse(input: string, expected: any, options?: ParseOptions): void {
	var errors: { error: ParseErrorCode }[] = [];
	var actual = parse(input, errors, options);

	assert(errors.length > 0);
	assert.deepEqual(actual, expected);
}
開發者ID:m-khosravi,項目名稱:vscode,代碼行數:7,代碼來源:json.test.ts

示例3: assertInvalidParse

function assertInvalidParse(input:string, expected:any) : void {
	var errors : ParseError[] = [];
	var actual = parse(input, errors);

	assert(errors.length > 0);
	assert.deepEqual(actual, expected);
}
開發者ID:Dineshkumar-Ponnusamy,項目名稱:vscode,代碼行數:7,代碼來源:json.test.ts

示例4: assertValidParse

function assertValidParse(input: string, expected: any, options?: ParseOptions): void {
	var errors: { error: ParseErrorCode }[] = [];
	var actual = parse(input, errors, options);

	if (errors.length !== 0) {
		assert(false, getParseErrorMessage(errors[0].error));
	}
	assert.deepEqual(actual, expected);
}
開發者ID:m-khosravi,項目名稱:vscode,代碼行數:9,代碼來源:json.test.ts

示例5: assertValidParse

function assertValidParse(input:string, expected:any) : void {
	var errors : string[] = [];
	var actual = parse(input, errors);

	if (errors.length !== 0) {
		assert(false, errors[0]);
	}
	assert.deepEqual(actual, expected);
}
開發者ID:13572293130,項目名稱:vscode,代碼行數:9,代碼來源:json.test.ts

示例6: doParseStoredWorkspace

function doParseStoredWorkspace(path: URI, contents: string): IStoredWorkspace {

	// Parse workspace file
	let storedWorkspace: IStoredWorkspace = json.parse(contents); // use fault tolerant parser

	// Filter out folders which do not have a path or uri set
	if (Array.isArray(storedWorkspace.folders)) {
		storedWorkspace.folders = storedWorkspace.folders.filter(folder => isStoredWorkspaceFolder(folder));
	}

	// Validate
	if (!Array.isArray(storedWorkspace.folders)) {
		throw new Error(`${path} looks like an invalid workspace file.`);
	}

	return storedWorkspace;
}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:17,代碼來源:workspaces.ts


注:本文中的vs/base/common/json.parse函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。