mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
60 lines
6.5 KiB
JSON
60 lines
6.5 KiB
JSON
|
{
|
||
|
"data": {
|
||
|
"question": {
|
||
|
"questionId": "2745",
|
||
|
"questionFrontendId": "2633",
|
||
|
"boundTopicId": null,
|
||
|
"title": "Convert Object to JSON String",
|
||
|
"titleSlug": "convert-object-to-json-string",
|
||
|
"content": "<p>Given an object, return a valid JSON string of that object. You may assume the object only inludes strings, integers, arrays, objects, booleans, and null. The returned string should not include extra spaces. The order of keys should be the same as the order returned by <code>Object.keys()</code>.</p>\n\n<p>Please solve it without using the built-in <code>JSON.stringify</code> method.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> object = {"y":1,"x":2}\n<strong>Output:</strong> {"y":1,"x":2}\n<strong>Explanation:</strong> \nReturn the JSON representation.\nNote that the order of keys should be the same as the order returned by Object.keys().</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> object = {"a":"str","b":-12,"c":true,"d":null}\n<strong>Output:</strong> {"a":"str","b":-12,"c":true,"d":null}\n<strong>Explanation:</strong>\nThe primitives of JSON are strings, numbers, booleans, and null.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> object = {"key":{"a":1,"b":[{},null,"Hello"]}}\n<strong>Output:</strong> {"key":{"a":1,"b":[{},null,"Hello"]}}\n<strong>Explanation:</strong>\nObjects and arrays can include other objects and arrays.\n</pre>\n\n<p><strong class=\"example\">Example 4:</strong></p>\n\n<pre>\n<strong>Input:</strong> object = true\n<strong>Output:</strong> true\n<strong>Explanation:</strong>\nPrimitive types are valid inputs.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>object includes strings, integers, booleans, arrays, objects, and null</code></li>\n\t<li><code>1 <= JSON.stringify(object).length <= 10<sup>5</sup></code></li>\n\t<li><code>maxNestingLevel <= 1000</code></li>\n</ul>\n",
|
||
|
"translatedTitle": null,
|
||
|
"translatedContent": null,
|
||
|
"isPaidOnly": false,
|
||
|
"difficulty": "Medium",
|
||
|
"likes": 15,
|
||
|
"dislikes": 3,
|
||
|
"isLiked": null,
|
||
|
"similarQuestions": "[{\"title\": \"JSON Deep Equal\", \"titleSlug\": \"json-deep-equal\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Flatten Deeply Nested Array\", \"titleSlug\": \"flatten-deeply-nested-array\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
|
||
|
"exampleTestcases": "{\"y\":1,\"x\":2}\n{\"a\":\"str\",\"b\":-12,\"c\":true,\"d\":null}\n{\"key\":{\"a\":1,\"b\":[{},null,\"Hello\"]}}\ntrue",
|
||
|
"categoryTitle": "JavaScript",
|
||
|
"contributors": [],
|
||
|
"topicTags": [],
|
||
|
"companyTagStats": null,
|
||
|
"codeSnippets": [
|
||
|
{
|
||
|
"lang": "JavaScript",
|
||
|
"langSlug": "javascript",
|
||
|
"code": "/**\n * @param {any} object\n * @return {string}\n */\nvar jsonStringify = function(object) {\n \n};",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
},
|
||
|
{
|
||
|
"lang": "TypeScript",
|
||
|
"langSlug": "typescript",
|
||
|
"code": "function jsonStringify(object: any): string {\n\n};",
|
||
|
"__typename": "CodeSnippetNode"
|
||
|
}
|
||
|
],
|
||
|
"stats": "{\"totalAccepted\": \"347\", \"totalSubmission\": \"442\", \"totalAcceptedRaw\": 347, \"totalSubmissionRaw\": 442, \"acRate\": \"78.5%\"}",
|
||
|
"hints": [
|
||
|
"Consider the 4 possibilities. The object could be an array, an object, a string, or another type.",
|
||
|
"Think about the problem recursively. If you know how to convert any sub-data into a string, how could you use it to convert the entire data into a string?",
|
||
|
"If the data is a string, it's just the value surrounded by double quotes. If the data is another type, its just String(data). If the data is an array, it's the recursively stringified value of each item separated by commas. If the data is an object, it's a series of key-value pairs where each value is the recursively stringified value."
|
||
|
],
|
||
|
"solution": null,
|
||
|
"status": null,
|
||
|
"sampleTestCase": "{\"y\":1,\"x\":2}",
|
||
|
"metaData": "{\n \"name\": \"jsonStringify\",\n \"params\": [\n {\n \"name\": \"object\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}",
|
||
|
"judgerAvailable": true,
|
||
|
"judgeType": "large",
|
||
|
"mysqlSchemas": [],
|
||
|
"enableRunCode": true,
|
||
|
"enableTestMode": false,
|
||
|
"enableDebugger": false,
|
||
|
"envInfo": "{\"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use 5.3.0 version of <a href=\\\"https://github.com/datastructures-js/priority-queue/tree/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and 4.2.1 version of <a href=\\\"https://github.com/datastructures-js/queue/tree/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 4.5.4, Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES2020 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\"]}",
|
||
|
"libraryUrl": null,
|
||
|
"adminUrl": null,
|
||
|
"challengeQuestion": null,
|
||
|
"__typename": "QuestionNode"
|
||
|
}
|
||
|
}
|
||
|
}
|