{"id":3761,"date":"2023-12-25T21:34:01","date_gmt":"2023-12-25T13:34:01","guid":{"rendered":"http:\/\/www.ponybai.com\/?p=3761"},"modified":"2023-11-27T21:40:49","modified_gmt":"2023-11-27T13:40:49","slug":"json-%e6%94%af%e6%8c%81","status":"publish","type":"post","link":"http:\/\/www.ponybai.com\/?p=3761","title":{"rendered":"JSON \u652f\u6301"},"content":{"rendered":"\n<p>Apex \u4e2d\u7684 JavaScript \u5bf9\u8c61\u8868\u793a\u6cd5 \uff08JSON\uff09 \u652f\u6301\u53ef\u5b9e\u73b0 Apex \u7684\u5e8f\u5217\u5316 \u5bf9\u8c61\u8f6c\u6362\u4e3aJSON\u683c\u5f0f\uff0c\u5e76\u5bf9\u5e8f\u5217\u5316\u7684JSON\u5185\u5bb9\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\u3002Apex \u63d0\u4f9b\u4e86\u4e00\u7ec4\u7c7b\uff0c\u7528\u4e8e\u516c\u5f00 JSON \u5e8f\u5217\u5316\u7684\u65b9\u6cd5\u548c \u53cd\u5e8f\u5217\u5316\u3002\u4e0b\u8868\u63cf\u8ff0\u4e86\u53ef\u7528\u7684\u7c7b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u7c7b<\/th><th>\u63cf\u8ff0<\/th><\/tr><\/thead><tbody><tr><td><samp>System.JSON<\/samp><\/td><td>\u5305\u542b\u7528\u4e8e\u5c06 Apex \u5bf9\u8c61\u5e8f\u5217\u5316\u4e3a JSON \u683c\u5f0f\u7684\u65b9\u6cd5\uff0c\u4ee5\u53ca \u53cd\u5e8f\u5217\u5316\u4f7f\u7528\u6b64\u7c7b\u4e2d\u7684\u65b9\u6cd5\u5e8f\u5217\u5316\u7684 JSON \u5185\u5bb9\u3002<samp>serialize<\/samp><\/td><\/tr><tr><td><samp>System.JSONGenerator<\/samp><\/td><td>\u5305\u542b\u7528\u4e8e\u4f7f\u7528\u6807\u51c6\u5c06\u5bf9\u8c61\u5e8f\u5217\u5316\u4e3a JSON \u5185\u5bb9\u7684\u65b9\u6cd5 JSON \u7f16\u7801\u3002<\/td><\/tr><tr><td><samp>System.JSONParser<\/samp><\/td><td>\u8868\u793a JSON \u7f16\u7801\u5185\u5bb9\u7684\u5206\u6790\u5668\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u679a\u4e3e\u5305\u542b\u6807\u8bb0 \u7528\u4e8e JSON \u89e3\u6790\u3002<samp>System.JSONToken<\/samp><\/p>\n\n\n\n<p>\u8fd9\u4e9b\u7c7b\u4e2d\u7684\u65b9\u6cd5\u4f1a\u629b\u51fa\u4e00\u4e2a if \u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u9047\u5230\u95ee\u9898\u3002<samp>JSONException<\/samp>JSON \u652f\u6301\u6ce8\u610f\u4e8b\u9879<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>JSON \u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u652f\u6301\u53ef\u7528\u4e8e sObjects\uff08\u6807\u51c6 \u5bf9\u8c61\u548c\u81ea\u5b9a\u4e49\u5bf9\u8c61\uff09\u3001Apex \u539f\u8bed\u548c\u96c6\u5408\u7c7b\u578b\u3001\u8fd4\u56de\u7c7b\u578b \u6570\u636e\u5e93\u65b9\u6cd5\uff08\u4f8b\u5982 SaveResult \u548c DeleteResult\uff09\u548c Apex \u5b9e\u4f8b \u7c7b\u3002<\/li>\n\n\n\n<li>\u53ea\u6709\u6258\u7ba1\u5305\u7684\u81ea\u5b9a\u4e49\u5bf9\u8c61\uff08\u7c7b\u578b\uff09\u624d\u80fd\u4ece\u4ee5\u4e0b\u4ee3\u7801\u8fdb\u884c\u5e8f\u5217\u5316\uff1a \u6258\u7ba1\u5305\u7684\u5916\u90e8\u3002\u4f5c\u4e3a \u4e2d\u5b9a\u4e49\u7684 Apex \u7c7b\u5b9e\u4f8b\u7684\u5bf9\u8c61 \u65e0\u6cd5\u5e8f\u5217\u5316\u6258\u7ba1\u5305\u3002<samp>sObject<\/samp><\/li>\n\n\n\n<li><a><\/a>\u4ec5\u5f53 Map \u5bf9\u8c61\u4f7f\u7528 \u4ee5\u4e0b\u6570\u636e\u7c7b\u578b\u4f5c\u4e3a\u952e\u3002<a><\/a>\n<ul class=\"wp-block-list\">\n<li>\u5e03\u5c14<\/li>\n\n\n\n<li>\u65e5\u671f<\/li>\n\n\n\n<li>\u65e5\u671f\u65f6\u95f4<\/li>\n\n\n\n<li>\u5341\u8fdb\u5236<\/li>\n\n\n\n<li>\u53cc<\/li>\n\n\n\n<li>\u679a\u4e3e<\/li>\n\n\n\n<li>\u540c\u4e0a<\/li>\n\n\n\n<li>\u6574\u6570<\/li>\n\n\n\n<li>\u957f<\/li>\n\n\n\n<li>\u5b57\u7b26\u4e32<\/li>\n\n\n\n<li>\u65f6\u95f4<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u5f53\u5bf9\u8c61\u88ab\u58f0\u660e\u4e3a\u7236\u7c7b\u578b\uff0c\u4f46\u88ab\u8bbe\u7f6e\u4e3a \u5b50\u7c7b\u578b\uff0c\u67d0\u4e9b\u6570\u636e\u53ef\u80fd\u4f1a\u4e22\u5931\u3002\u8be5\u5bf9\u8c61\u88ab\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u4e3a \u7236\u7c7b\u578b\u548c\u7279\u5b9a\u4e8e\u5b50\u7c7b\u578b\u7684\u4efb\u4f55\u5b57\u6bb5\u90fd\u5c06\u4e22\u5931\u3002<\/li>\n\n\n\n<li>\u5177\u6709\u81ea\u8eab\u5f15\u7528\u7684\u5bf9\u8c61\u4e0d\u4f1a\u88ab\u5e8f\u5217\u5316\uff0c\u5e76\u5bfc\u81f4\u629b\u51fa\u3002<samp>JSONException<\/samp><\/li>\n\n\n\n<li>\u4e24\u6b21\u5f15\u7528\u540c\u4e00\u5bf9\u8c61\u7684\u5f15\u7528\u56fe\u5c06\u88ab\u53cd\u5e8f\u5217\u5316\u5e76\u5bfc\u81f4 \u8981\u751f\u6210\u7684\u5f15\u7528\u5bf9\u8c61\u7684\u591a\u4e2a\u526f\u672c\u3002<\/li>\n\n\n\n<li>\u6570\u636e\u7c7b\u578b\u4e0d\u662f \u5e8f\u5217 \u5316\u3002\u5982\u679c\u5c1d\u8bd5\u521b\u5efa\u53ef\u5e8f\u5217\u5316\u7c7b\u7684\u5b9e\u4f8b\uff0c\u4f8b\u5982 Visualforce \u63a7\u5236\u5668\uff0c\u5176\u6210\u5458\u53d8\u91cf\u7c7b\u578b\u4e3a \uff0c\u60a8\u4f1a\u6536\u5230\u5f02\u5e38\u3002\u82e5\u8981\u5728\u53ef\u5e8f\u5217\u5316\u7c7b\u4e2d\u4f7f\u7528\uff0c\u8bf7\u4f7f\u7528 local \u53d8\u91cf\u3002<samp>System.JSONParser<\/samp><samp>System.JSONParser<\/samp><samp>JSONParser<\/samp><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u7248\u672c\u5316\u884c\u4e3a\u66f4\u6539<\/h2>\n\n\n\n<p>\u5728 API \u7248\u672c 53.0 \u53ca\u66f4\u9ad8\u7248\u672c\u4e2d\uff0cDateTime \u683c\u5f0f\u548c\u5904\u7406\u5df2\u66f4\u65b0\u3002The API \u6b63\u786e\u5904\u7406 JSON \u8bf7\u6c42\u4e2d\u4f7f\u7528 3 \u4f4d\u4ee5\u4e0a\u6570\u5b57\u7684 JSON\u8bf7\u6c42\u4e2d\u7684DateTime\u503c \u5c0f\u6570\u70b9\u3002\u4f7f\u7528\u4e0d\u652f\u6301\u7684 DateTime \u683c\u5f0f\uff08\u5982 \uff09\u7684\u8bf7\u6c42\u4f1a\u5bfc\u81f4\u9519\u8bef\u3002Salesforce \u5efa\u8bae\u60a8 \u4e25\u683c\u9075\u5b88\u00a0https:\/\/developer.salesforce.com\/docs\/atlas.en-us.api_rest.meta\/api_rest\/intro_valid_date_formats.htm\u00a0\u4e2d\u6307\u5b9a\u7684 DateTime \u683c\u5f0f\u3002<samp>123456000<\/samp><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5f80\u8fd4\u5e8f\u5217\u5316<strong>\u548c\u53cd\u5e8f\u5217\u5316<\/strong><br>\u4f7f\u7528\u7c7b\u65b9\u6cd5\u5bf9 JSON \u5185\u5bb9\u6267\u884c\u5f80\u8fd4\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c06\u5bf9\u8c61\u5e8f\u5217\u5316\u4e3a JSON \u683c\u5f0f\u7684\u5b57\u7b26\u4e32\uff0c\u5e76\u5c06 JSON \u5b57\u7b26\u4e32\u53cd\u5e8f\u5217\u5316\u56de\u5bf9\u8c61\u3002<samp>JSON<\/samp><\/li>\n\n\n\n<li>JSON\u00a0<strong>\u751f\u6210\u5668<\/strong><br>\u4f7f\u7528\u7c7b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u751f\u6210\u6807\u51c6\u7684 JSON \u7f16\u7801\u5185\u5bb9\u3002<samp>JSONGenerator<\/samp><\/li>\n\n\n\n<li>JSON\u00a0<strong>\u89e3\u6790<\/strong><br>\u4f7f\u7528\u7c7b\u65b9\u6cd5\u89e3\u6790 JSON \u7f16\u7801\u7684\u5185\u5bb9\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5206\u6790\u4ece\u5bf9\u5916\u90e8\u670d\u52a1\uff08\u5982 Web \u670d\u52a1\u6807\u6ce8\uff09\u7684\u8c03\u7528\u8fd4\u56de\u7684 JSON \u683c\u5f0f\u7684\u54cd\u5e94\u3002<samp>JSONParser<\/samp><\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">\u5f80\u8fd4\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316<\/h1>\n\n\n\n<p>\u4f7f\u7528\u7c7b\u65b9\u6cd5\u6267\u884c\u5f80\u8fd4 JSON \u5185\u5bb9\u7684\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u3002\u8fd9\u4e9b\u65b9\u6cd5\u4f7f\u60a8\u80fd\u591f \u5c06\u5bf9\u8c61\u5e8f\u5217\u5316\u4e3a JSON \u683c\u5f0f\u7684\u5b57\u7b26\u4e32\uff0c\u5e76\u5c06 JSON \u5b57\u7b26\u4e32\u53cd\u5e8f\u5217\u5316\u56de \u5bf9\u8c61\u3002<\/p>\n\n\n\n<p><samp>JSON<\/samp><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u53d1\u7968\u5217\u8868<\/h2>\n\n\n\n<p>\u6b64\u793a\u4f8b\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u5217\u8868\u5e76\u5e8f\u5217\u5316\u8be5\u5217\u8868\u3002\u63a5\u4e0b\u6765\uff0c\u5e8f\u5217\u5316 JSON \u5b57\u7b26\u4e32\u7528\u4e8e\u518d\u6b21\u53cd\u5e8f\u5217\u5316\u5217\u8868\uff0c\u793a\u4f8b\u9a8c\u8bc1 \u65b0\u5217\u8868\u5305\u542b\u4e0e\u539f\u59cb\u5217\u8868\u4e2d\u76f8\u540c\u7684\u53d1\u7968 \u5217\u8868\u3002<\/p>\n\n\n\n<p><samp>InvoiceStatement<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class JSONRoundTripSample {\n  \n    public class InvoiceStatement {\n        Long invoiceNumber;\n        Datetime statementDate;\n        Decimal totalPrice;\n        \n        public InvoiceStatement(Long i, Datetime dt, Decimal price)\n        {\n            invoiceNumber = i;\n            statementDate = dt;\n            totalPrice = price;\n        }\n    }\n    \n    public static void SerializeRoundtrip() {\n        Datetime dt = Datetime.now(); \n        \/\/ Create a few invoices.\n        InvoiceStatement inv1 = new InvoiceStatement(1,Datetime.valueOf(dt),1000);\n        InvoiceStatement inv2 = new InvoiceStatement(2,Datetime.valueOf(dt),500);\n        \/\/ Add the invoices to a list.\n        List&lt;InvoiceStatement&gt; invoices = new List&lt;InvoiceStatement&gt;();\n        invoices.add(inv1);\n        invoices.add(inv2);\n              \n        \/\/ Serialize the list of InvoiceStatement objects.\n        String JSONString = JSON.serialize(invoices);\n        System.debug('Serialized list of invoices into JSON format: ' + JSONString);\n        \n        \/\/ Deserialize the list of invoices from the JSON string.\n        List&lt;InvoiceStatement&gt; deserializedInvoices = \n          (List&lt;InvoiceStatement&gt;)JSON.deserialize(JSONString, List&lt;InvoiceStatement&gt;.class);\n        System.assertEquals(invoices.size(), deserializedInvoices.size());\n        Integer i=0;\n        for (InvoiceStatement deserializedInvoice :deserializedInvoices) {\n            system.debug('Deserialized:' + deserializedInvoice.invoiceNumber + ',' \n            + deserializedInvoice.statementDate.formatGmt('MM\/dd\/yyyy  HH:mm:ss.SSS')\n            + ', ' + deserializedInvoice.totalPrice); \n            system.debug('Original:' + invoices&#91;i].invoiceNumber + ',' \n            + invoices&#91;i].statementDate.formatGmt('MM\/dd\/yyyy  HH:mm:ss.SSS') \n            + ', ' + invoices&#91;i].totalPrice); \n            i++;\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">JSON \u5e8f\u5217\u5316\u6ce8\u610f\u4e8b\u9879<\/h2>\n\n\n\n<p>\u8be5\u65b9\u6cd5\u7684\u884c\u4e3a\u4e0d\u540c \u53d6\u51b3\u4e8e\u4fdd\u5b58\u7684 Apex \u4ee3\u7801\u7684 Salesforce API \u7248\u672c\u3002<samp>serialize<\/samp>\u4f7f\u7528\u8bbe\u7f6e\u5176\u4ed6\u5b57\u6bb5\u7684\u67e5\u8be2 sObject \u7684\u5e8f\u5217\u5316\u5bf9\u4e8e\u4f7f\u7528 Salesforce API \u7248\u672c 27.0 \u53ca\u66f4\u65e9\u7248\u672c\u4fdd\u5b58\u7684 Apex\uff0c\u5982\u679c\u67e5\u8be2 sObjects \u8bbe\u7f6e\u4e86\u5176\u4ed6\u5b57\u6bb5\uff0c\u8fd9\u4e9b\u5b57\u6bb5\u4e0d\u5305\u542b\u5728 \u65b9\u6cd5\u8fd4\u56de\u7684\u5e8f\u5217\u5316 JSON \u5b57\u7b26\u4e32\u3002\u4ece\u4f7f\u7528 Salesforce \u4fdd\u5b58\u7684 Apex \u5f00\u59cb API \u7248\u672c 28.0\uff0c\u5176\u4ed6\u5b57\u6bb5\u5305\u542b\u5728\u5e8f\u5217\u5316\u7684 JSON \u4e2d \u5b57\u7b26\u4e32\u3002<samp>serialize<\/samp>\u672c\u793a\u4f8b\u5728\u67e5\u8be2\u8054\u7cfb\u4eba\u540e\u5411\u8be5\u8054\u7cfb\u4eba\u6dfb\u52a0\u4e00\u4e2a\u5b57\u6bb5\uff0c\u7136\u540e \u5e8f\u5217\u5316\u8054\u7cfb\u4eba\u3002\u65ad\u8a00\u8bed\u53e5\u9a8c\u8bc1 JSON string \u5305\u542b\u9644\u52a0\u5b57\u6bb5\u3002\u65ad\u8a00\u4f20\u9012 Apex \u4fdd\u5b58 \u4f7f\u7528 Salesforce API \u7248\u672c 28.0 \u548c \u540e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Contact con = &#91;SELECT Id, LastName, AccountId FROM Contact LIMIT 1]; \n\/\/ Set additional field\ncon.FirstName = 'Joe'; \nString jsonstring = Json.serialize(con); \nSystem.debug(jsonstring); \nSystem.assert(jsonstring.contains('Joe') == true);<\/code><\/pre>\n\n\n\n<p>\u805a\u5408\u67e5\u8be2\u7ed3\u679c\u5b57\u6bb5\u7684\u5e8f\u5217\u5316\u5bf9\u4e8e\u4f7f\u7528 Salesforce API \u7248\u672c 27.0 \u4fdd\u5b58\u7684 Apex\uff0c\u805a\u5408\u7ed3\u679c \u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\uff0c\u67e5\u8be2\u4e0d\u5305\u62ec SELECT \u8bed\u53e5\u4e2d\u7684\u5b57\u6bb5 \u4f7f\u7528\u8be5\u65b9\u6cd5\u5e8f\u5217\u5316\u3002\u5bf9\u4e8e\u65e9\u671f API \u7248\u672c\u6216 API \u7248\u672c 28.0 \u53ca\u66f4\u9ad8\u7248\u672c\uff0c \u5e8f\u5217\u5316\u805a\u5408\u67e5\u8be2\u7ed3\u679c\u5305\u62ec SELECT \u4e2d\u7684\u6240\u6709\u5b57\u6bb5 \u9648\u8ff0\u3002<samp>serialize<\/samp>\u6b64\u805a\u5408\u67e5\u8be2\u8fd4\u56de\u4e24\u4e2a\u5b57\u6bb5\uff1aID \u5b57\u6bb5\u8ba1\u6570\u548c \u5e10\u6237\u540d\u79f0\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String jsonString = JSON.serialize(\n    Database.query('SELECT Count(Id),Account.Name FROM Contact WHERE Account.Name != null GROUP BY Account.Name LIMIT 1'));\n    System.debug(jsonString);\n\n\/\/ Expected output in API v 26 and earlier or v28 and later\n\/\/ &#91;{\"attributes\":{\"type\":\"AggregateResult\"},\"expr0\":2,\"Name\":\"acct1\"}]<\/code><\/pre>\n\n\n\n<p>\u7a7a\u5b57\u6bb5\u7684\u5e8f\u5217\u5316\u4ece API \u7248\u672c 28.0 \u5f00\u59cb\uff0cnull \u5b57\u6bb5\u4e0d\u4f1a\u5e8f\u5217\u5316\uff0c\u4e5f\u4e0d\u4f1a \u5305\u542b\u5728 JSON \u5b57\u7b26\u4e32\u4e2d\uff0c\u8fd9\u4e0e\u65e9\u671f\u7248\u672c\u4e0d\u540c\u3002\u6b64\u66f4\u6539\u4e0d\u4f1a \u5f71\u54cd\u4f7f\u7528 JSON \u65b9\u6cd5\uff08\u4f8b\u5982\u00a0Json.deserialize\uff08\uff09\uff09\u53cd\u5e8f\u5217\u5316 JSON \u5b57\u7b26\u4e32\u3002\u6b64\u66f4\u6539\u662f \u68c0\u67e5 JSON \u5b57\u7b26\u4e32\u65f6\u4f1a\u6ce8\u610f\u5230\u8fd9\u4e00\u70b9\u3002\u4e3a \u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String jsonString = JSON.serialize(\n                 &#91;SELECT Id, Name, Website FROM Account WHERE Website = null LIMIT 1]);\nSystem.debug(jsonString);\n\n\/\/ In v27.0 and earlier, the string includes the null field and looks like the following.\n\/\/ {\"attributes\":{...},\"Id\":\"001D000000Jsm0WIAR\",\"Name\":\"Acme\",\"Website\":null}\n\n\/\/ In v28.0 and later, the string doesn\u2019t include the null field and looks like \n\/\/  the following.\n\/\/ {\"attributes\":{...},\"Name\":\"Acme\",\"Id\":\"001D000000Jsm0WIAR\"}}<\/code><\/pre>\n\n\n\n<p>ID \u5e8f\u5217\u5316\u5728 API \u7248\u672c 34.0 \u53ca\u66f4\u65e9\u7248\u672c\u4e2d\uff0c\u5bf9\u4e8e\u5df2\u901a\u8fc7 \u5f80\u8fd4 JSON \u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u3002<samp>==<\/samp><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">JSON \u53cd\u5e8f\u5217\u5316\u6ce8\u610f\u4e8b\u9879<\/h2>\n\n\n\n<p>\u805a\u5408\u7ed3\u679c\u4e2d\u7684 JSON \u65e0\u6cd5\u53cd\u5e8f\u5217\u5316\u56de Apex AggregateResult \u5bf9\u8c61\uff0c\u56e0\u4e3a\u5b83\u4eec\u6ca1\u6709\u547d\u540d\u5b57\u6bb5\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">JSON\u751f\u6210\u5668<\/h1>\n\n\n\n<p>\u4f7f\u7528\u7c7b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u751f\u6210\u6807\u51c6\u7684 JSON \u7f16\u7801\u5185\u5bb9\u3002<\/p>\n\n\n\n<p><samp>JSONGenerator<\/samp><\/p>\n\n\n\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6\u9010\u4e2a\u5143\u7d20\u6784\u9020 JSON \u5185\u5bb9 JSON \u7f16\u7801\u3002\u4e3a\u6b64\uff0c\u8bf7\u4f7f\u7528\u7c7b\u4e2d\u7684\u65b9\u6cd5\u3002<samp>JSONGenerator<\/samp><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">JSONGenerator \u793a\u4f8b<\/h2>\n\n\n\n<p>\u6b64\u793a\u4f8b\u751f\u6210 \u4f7f\u7528\u7c7b\u7684\u65b9\u6cd5\u4ee5\u6f02\u4eae\u7684\u6253\u5370\u683c\u5f0f\u521b\u5efa JSON \u5b57\u7b26\u4e32\u3002\u9996\u5148\u4e3e\u4e2a\u4f8b\u5b50 \u6dfb\u52a0\u4e00\u4e2a\u6570\u5b57\u5b57\u6bb5\u548c\u4e00\u4e2a\u5b57\u7b26\u4e32\u5b57\u6bb5\uff0c\u7136\u540e\u6dfb\u52a0\u4e00\u4e2a\u8981\u5305\u542b\u7684\u5b57\u6bb5 \u6574\u6570\u5217\u8868\u7684 object \u5b57\u6bb5\uff0c\u8be5\u5b57\u6bb5\u5df2\u6b63\u786e\u53cd\u5e8f\u5217\u5316\u3002 \u63a5\u4e0b\u6765\uff0c\u5b83\u6dfb\u52a0\u5bf9\u8c61 \u8fdb\u5165\u73b0\u573a\uff0c\u5176\u4e2d \u4e5f\u4f1a\u88ab\u53cd\u5e8f\u5217\u5316\u3002<samp>JSONGenerator<\/samp><samp>A<\/samp><samp>Object&nbsp;A<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class JSONGeneratorSample{\n\n    public class A { \n        String str;\n        \n        public A(String s) { str = s; }\n    }\n\n    static void generateJSONContent() {\n        \/\/ Create a JSONGenerator object.\n        \/\/ Pass true to the constructor for pretty print formatting.\n        JSONGenerator gen = JSON.createGenerator(true);\n        \n        \/\/ Create a list of integers to write to the JSON string.\n        List&lt;integer&gt; intlist = new List&lt;integer&gt;();\n        intlist.add(1);\n        intlist.add(2);\n        intlist.add(3);\n        \n        \/\/ Create an object to write to the JSON string.\n        A x = new A('X');\n        \n        \/\/ Write data to the JSON string.\n        gen.writeStartObject();\n        gen.writeNumberField('abc', 1.21);\n        gen.writeStringField('def', 'xyz');\n        gen.writeFieldName('ghi');\n        gen.writeStartObject();\n        \n        gen.writeObjectField('aaa', intlist);\n        \n        gen.writeEndObject();\n        \n        gen.writeFieldName('Object A');\n        \n        gen.writeObject(x);\n        \n        gen.writeEndObject();\n        \n        \/\/ Get the JSON string.\n        String pretty = gen.getAsString();\n        \n        System.assertEquals('{\\n' +\n        '  \"abc\" : 1.21,\\n' +\n        '  \"def\" : \"xyz\",\\n' +\n        '  \"ghi\" : {\\n' +\n        '    \"aaa\" : &#91; 1, 2, 3 ]\\n' +\n        '  },\\n' +\n        '  \"Object A\" : {\\n' +\n        '    \"str\" : \"X\"\\n' +\n        '  }\\n' +\n        '}', pretty);\n    }\n}<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">JSON\u89e3\u6790<\/h1>\n\n\n\n<p>\u4f7f\u7528\u7c7b\u65b9\u6cd5\u8fdb\u884c\u89e3\u6790 JSON \u7f16\u7801\u7684\u5185\u5bb9\u3002\u8fd9\u4e9b\u65b9\u6cd5\u4f7f\u4f60\u80fd\u591f\u5206\u6790 JSON \u683c\u5f0f\u7684\u54cd\u5e94\uff0c\u8be5\u54cd\u5e94\u662f \u4ece\u5bf9\u5916\u90e8\u670d\u52a1\uff08\u5982 Web \u670d\u52a1\u6807\u6ce8\uff09\u7684\u8c03\u7528\u8fd4\u56de\u3002<\/p>\n\n\n\n<p><samp>JSONParser<\/samp><\/p>\n\n\n\n<p>\u4ee5\u4e0b\u793a\u4f8b\u6f14\u793a\u5982\u4f55\u5206\u6790 JSON \u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u89e3\u6790\u6765\u81ea Web \u670d\u52a1\u6807\u6ce8\u7684 JSON \u54cd\u5e94<\/h2>\n\n\n\n<p>\u6b64\u793a\u4f8b\u4f7f\u7528\u65b9\u6cd5\u5206\u6790 JSON \u683c\u5f0f\u7684\u54cd\u5e94\u3002\u5b83\u5bf9\u8fd4\u56de JSON \u683c\u5f0f\u7684\u54cd\u5e94\u3002\u63a5\u4e0b\u6765\uff0c\u89e3\u6790\u54cd\u5e94\u4ee5\u4ece api \u6784\u5efa\u6620\u5c04 \u7248\u672c\u53f7\u6dfb\u52a0\u5230\u7248\u672c\u6807\u7b7e\u4e2d\u3002<samp>JSONParser<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class JSONParserUtil {\n    public static void parseJSONResponse() {        \n        \n        \/\/ Create HTTP request to send.\n        HttpRequest request = new HttpRequest();\n        \/\/ Set the endpoint URL.\n        String endpoint = URL.getOrgDomainUrl().toExternalForm() + '\/services\/data';\n        request.setEndPoint(endpoint);\n        \/\/ Set the HTTP verb to GET.\n        request.setMethod('GET');\n        \/\/ Set the request header for JSON content type\n        request.setHeader('Accept', 'application\/json');\n        \n        \/\/ Send the HTTP request and get the response.\n        \/\/ The response is in JSON format.\n        Http httpProtocol = new Http();\n        HttpResponse response = httpProtocol.send(request);\n        System.debug(response.getBody());\n        \/* The JSON response returned is the following:\n            {\"label\":\"Summer '14\",\"url\":\"\/services\/data\/v31.0\",\"version\":\"31.0\"},\n            {\"label\":\"Winter '15\",\"url\":\"\/services\/data\/v32.0\",\"version\":\"32.0\"},\n            {\"label\":\"Spring '15\",\"url\":\"\/services\/data\/v33.0\",\"version\":\"33.0\"},\n        *\/\n        \/\/ Parse JSON response to build a map from API version numbers to labels\n        JSONParser parser = JSON.createParser(response.getBody());\n        Map&lt;double, string&gt; apiVersionToReleaseNameMap = new Map&lt;double, string&gt;();\n        \n        string label = null;\n        double version = null;\n        \n        while (parser.nextToken() != null) {\n            \n            if (parser.getCurrentToken() == JSONToken.FIELD_NAME) {\n                switch on parser.getText() {\n                    when 'label' {\n                    \/\/ Advance to the label value.\n                    parser.nextToken();\n                        label = parser.getText();\n                    }\n                    when 'version' {\n                        \/\/ Advance to the version value.\n                        parser.nextToken();\n                        version = Double.valueOf(parser.getText());\n                    }\n                }\n            }\n            \n            if(version != null &amp;&amp; String.isNotEmpty(label)) {\n                apiVersionToReleaseNameMap.put(version, label);\n                version = null;\n                label = null; \n            }\n        }\n        system.debug('Release with Rainbow logo = ' +\n            apiVersionToReleaseNameMap.get(39.0D));\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u89e3\u6790 JSON \u5b57\u7b26\u4e32\u5e76\u5c06\u5176\u53cd\u5e8f\u5217\u5316\u4e3a\u5bf9\u8c61<\/h2>\n\n\n\n<p>\u6b64\u793a\u4f8b\u4f7f\u7528\u786c\u7f16\u7801\u7684 JSON \u5b57\u7b26\u4e32\uff0c\u8be5\u5b57\u7b26\u4e32\u4e0e \u8fd4\u56de\u7684 JSON \u5b57\u7b26\u4e32\u76f8\u540c \u4e0a\u4e00\u793a\u4f8b\u4e2d\u7684\u6807\u6ce8\u3002\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u5c06\u5206\u6790\u6574\u4e2a\u5b57\u7b26\u4e32 \u4f7f\u7528\u8be5\u65b9\u6cd5\u6dfb\u52a0\u5230\u5bf9\u8c61\u4e2d\u3002 \u6b64\u4ee3\u7801\u8fd8\u4f7f\u7528 \u8df3\u8fc7\u5b50\u6570\u7ec4\u548c\u5b50\u5bf9\u8c61\uff0c\u5e76\u89e3\u6790 \u5217\u8868\u3002\u5206\u6790\u7684\u5bf9\u8c61\u662f\u5b9a\u4e49\u4e3a\u5185\u90e8\u7c7b\u7684\u7c7b\u7684\u5b9e\u4f8b\u3002\u56e0\u4e3a\u6bcf\u5f20\u53d1\u7968 \u5305\u542b\u884c\u9879\uff0c\u8868\u793a\u76f8\u5e94\u884c\u9879\u7c7b\u578b\u7684\u7c7b\uff0c\u8be5\u7c7b\uff0c\u4e5f\u88ab\u5b9a\u4e49\u4e3a \u5185\u90e8\u7c7b\u3002\u5c06\u6b64\u793a\u4f8b\u4ee3\u7801\u6dfb\u52a0\u5230\u8981\u4f7f\u7528\u7684\u7c7b\u4e2d \u5b83\u3002<\/p>\n\n\n\n<p><samp>Invoice<\/samp><samp><a><\/a>readValueAs<\/samp><samp>skipChildren<\/samp><samp>Invoice<\/samp><samp>LineItem<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static void parseJSONString() {\n    String jsonStr = \n        '{\"invoiceList\":&#91;' +\n        '{\"totalPrice\":5.5,\"statementDate\":\"2011-10-04T16:58:54.858Z\",\"lineItems\":&#91;' +\n            '{\"UnitPrice\":1.0,\"Quantity\":5.0,\"ProductName\":\"Pencil\"},' +\n            '{\"UnitPrice\":0.5,\"Quantity\":1.0,\"ProductName\":\"Eraser\"}],' +\n                '\"invoiceNumber\":1},' +\n        '{\"totalPrice\":11.5,\"statementDate\":\"2011-10-04T16:58:54.858Z\",\"lineItems\":&#91;' +\n            '{\"UnitPrice\":6.0,\"Quantity\":1.0,\"ProductName\":\"Notebook\"},' +\n            '{\"UnitPrice\":2.5,\"Quantity\":1.0,\"ProductName\":\"Ruler\"},' +\n            '{\"UnitPrice\":1.5,\"Quantity\":2.0,\"ProductName\":\"Pen\"}],\"invoiceNumber\":2}' +\n        ']}';\n\n    \/\/ Parse entire JSON response.\n    JSONParser parser = JSON.createParser(jsonStr);\n    while (parser.nextToken() != null) {\n        \/\/ Start at the array of invoices.\n        if (parser.getCurrentToken() == JSONToken.START_ARRAY) {\n            while (parser.nextToken() != null) {\n                \/\/ Advance to the start object marker to\n                \/\/  find next invoice statement object.\n                if (parser.getCurrentToken() == JSONToken.START_OBJECT) {\n                    \/\/ Read entire invoice object, including its array of line items.\n                    Invoice inv = (Invoice)parser.readValueAs(Invoice.class);\n                    system.debug('Invoice number: ' + inv.invoiceNumber);\n                    system.debug('Size of list items: ' + inv.lineItems.size());\n                    \/\/ For debugging purposes, serialize again to verify what was parsed.\n                    String s = JSON.serialize(inv);\n                    system.debug('Serialized invoice: ' + s);\n\n                    \/\/ Skip the child start array and start object markers.\n                    parser.skipChildren();\n                }\n            }\n        }\n    }\n} \n\n\/\/ Inner classes used for serialization by readValuesAs(). \n\npublic class Invoice {\n    public Double totalPrice;\n    public DateTime statementDate;\n    public Long invoiceNumber;\n    List&lt;LineItem&gt; lineItems;\n    \n    public Invoice(Double price, DateTime dt, Long invNumber, List&lt;LineItem&gt; liList) {\n        totalPrice = price;\n        statementDate = dt;\n        invoiceNumber = invNumber;\n        lineItems = liList.clone();\n    }\n}  \n\npublic class LineItem {\n    public Double unitPrice;\n    public Double quantity;\n    public String productName;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Apex \u4e2d\u7684 JavaScript \u5bf9\u8c61\u8868\u793a\u6cd5 \uff08JSON\uff09 \u652f\u6301\u53ef\u5b9e\u73b0 Apex \u7684\u5e8f\u5217\u5316 \u5bf9\u8c61\u8f6c\u6362\u4e3aJSON\u683c\u5f0f\uff0c\u5e76\u5bf9\u5e8f\u5217\u5316\u7684JSON\u5185\u5bb9\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\u3002Apex \u63d0\u4f9b\u4e86\u4e00\u7ec4\u7c7b\uff0c\u7528\u4e8e\u516c\u5f00 JSON \u5e8f\u5217\u5316\u7684\u65b9\u6cd5\u548c \u53cd\u5e8f\u5217\u5316\u3002\u4e0b\u8868\u63cf\u8ff0\u4e86\u53ef\u7528\u7684\u7c7b\u3002<\/p>\n","protected":false},"author":1,"featured_media":3762,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[199],"tags":[225],"class_list":["post-3761","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apex-","tag-apex-json"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JSON \u652f\u6301 - \u767d\u767d\u968f\u7b14<\/title>\n<meta name=\"description\" content=\"Apex \u4e2d\u7684 JavaScript \u5bf9\u8c61\u8868\u793a\u6cd5 \uff08JSON\uff09 \u652f\u6301\u53ef\u5b9e\u73b0 Apex \u7684\u5e8f\u5217\u5316 \u5bf9\u8c61\u8f6c\u6362\u4e3aJSON\u683c\u5f0f\uff0c\u5e76\u5bf9\u5e8f\u5217\u5316\u7684JSON\u5185\u5bb9\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\u3002Apex \u63d0\u4f9b\u4e86\u4e00\u7ec4\u7c7b\uff0c\u7528\u4e8e\u516c\u5f00 JSON \u5e8f\u5217\u5316\u7684\u65b9\u6cd5\u548c \u53cd\u5e8f\u5217\u5316\u3002\u4e0b\u8868\u63cf\u8ff0\u4e86\u53ef\u7528\u7684\u7c7b\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.ponybai.com\/?p=3761\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JSON \u652f\u6301 - \u767d\u767d\u968f\u7b14\" \/>\n<meta property=\"og:description\" content=\"Apex \u4e2d\u7684 JavaScript \u5bf9\u8c61\u8868\u793a\u6cd5 \uff08JSON\uff09 \u652f\u6301\u53ef\u5b9e\u73b0 Apex \u7684\u5e8f\u5217\u5316 \u5bf9\u8c61\u8f6c\u6362\u4e3aJSON\u683c\u5f0f\uff0c\u5e76\u5bf9\u5e8f\u5217\u5316\u7684JSON\u5185\u5bb9\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\u3002Apex \u63d0\u4f9b\u4e86\u4e00\u7ec4\u7c7b\uff0c\u7528\u4e8e\u516c\u5f00 JSON \u5e8f\u5217\u5316\u7684\u65b9\u6cd5\u548c \u53cd\u5e8f\u5217\u5316\u3002\u4e0b\u8868\u63cf\u8ff0\u4e86\u53ef\u7528\u7684\u7c7b\u3002\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.ponybai.com\/?p=3761\" \/>\n<meta property=\"og:site_name\" content=\"\u767d\u767d\u968f\u7b14\" \/>\n<meta property=\"article:published_time\" content=\"2023-12-25T13:34:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-27T13:40:49+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/11\/json.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1552\" \/>\n\t<meta property=\"og:image:height\" content=\"285\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"ponybai\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"ponybai\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/www.ponybai.com\/?p=3761#article\",\"isPartOf\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=3761\"},\"author\":{\"name\":\"ponybai\",\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\"},\"headline\":\"JSON \u652f\u6301\",\"datePublished\":\"2023-12-25T13:34:01+00:00\",\"dateModified\":\"2023-11-27T13:40:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=3761\"},\"wordCount\":168,\"publisher\":{\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\"},\"keywords\":[\"Apex Json\"],\"articleSection\":[\"Apex \u5f00\u53d1\u4eba\u5458\u6307\u5357\"],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.ponybai.com\/?p=3761\",\"url\":\"http:\/\/www.ponybai.com\/?p=3761\",\"name\":\"JSON \u652f\u6301 - \u767d\u767d\u968f\u7b14\",\"isPartOf\":{\"@id\":\"http:\/\/www.ponybai.com\/#website\"},\"datePublished\":\"2023-12-25T13:34:01+00:00\",\"dateModified\":\"2023-11-27T13:40:49+00:00\",\"description\":\"Apex \u4e2d\u7684 JavaScript \u5bf9\u8c61\u8868\u793a\u6cd5 \uff08JSON\uff09 \u652f\u6301\u53ef\u5b9e\u73b0 Apex \u7684\u5e8f\u5217\u5316 \u5bf9\u8c61\u8f6c\u6362\u4e3aJSON\u683c\u5f0f\uff0c\u5e76\u5bf9\u5e8f\u5217\u5316\u7684JSON\u5185\u5bb9\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\u3002Apex \u63d0\u4f9b\u4e86\u4e00\u7ec4\u7c7b\uff0c\u7528\u4e8e\u516c\u5f00 JSON \u5e8f\u5217\u5316\u7684\u65b9\u6cd5\u548c \u53cd\u5e8f\u5217\u5316\u3002\u4e0b\u8868\u63cf\u8ff0\u4e86\u53ef\u7528\u7684\u7c7b\u3002\",\"breadcrumb\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=3761#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.ponybai.com\/?p=3761\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.ponybai.com\/?p=3761#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"http:\/\/www.ponybai.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JSON \u652f\u6301\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.ponybai.com\/#website\",\"url\":\"http:\/\/www.ponybai.com\/\",\"name\":\"\u767d\u767d\u968f\u7b14\",\"description\":\"Salesforce\u5b98\u65b9\u8bb2\u5e08\",\"publisher\":{\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.ponybai.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\",\"name\":\"ponybai\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2025\/03\/cropped-Ihsans-WeChatQR.jpg\",\"contentUrl\":\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2025\/03\/cropped-Ihsans-WeChatQR.jpg\",\"width\":248,\"height\":248,\"caption\":\"ponybai\"},\"logo\":{\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/121.37.188.161\"],\"url\":\"http:\/\/www.ponybai.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JSON \u652f\u6301 - \u767d\u767d\u968f\u7b14","description":"Apex \u4e2d\u7684 JavaScript \u5bf9\u8c61\u8868\u793a\u6cd5 \uff08JSON\uff09 \u652f\u6301\u53ef\u5b9e\u73b0 Apex \u7684\u5e8f\u5217\u5316 \u5bf9\u8c61\u8f6c\u6362\u4e3aJSON\u683c\u5f0f\uff0c\u5e76\u5bf9\u5e8f\u5217\u5316\u7684JSON\u5185\u5bb9\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\u3002Apex \u63d0\u4f9b\u4e86\u4e00\u7ec4\u7c7b\uff0c\u7528\u4e8e\u516c\u5f00 JSON \u5e8f\u5217\u5316\u7684\u65b9\u6cd5\u548c \u53cd\u5e8f\u5217\u5316\u3002\u4e0b\u8868\u63cf\u8ff0\u4e86\u53ef\u7528\u7684\u7c7b\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.ponybai.com\/?p=3761","og_locale":"zh_CN","og_type":"article","og_title":"JSON \u652f\u6301 - \u767d\u767d\u968f\u7b14","og_description":"Apex \u4e2d\u7684 JavaScript \u5bf9\u8c61\u8868\u793a\u6cd5 \uff08JSON\uff09 \u652f\u6301\u53ef\u5b9e\u73b0 Apex \u7684\u5e8f\u5217\u5316 \u5bf9\u8c61\u8f6c\u6362\u4e3aJSON\u683c\u5f0f\uff0c\u5e76\u5bf9\u5e8f\u5217\u5316\u7684JSON\u5185\u5bb9\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\u3002Apex \u63d0\u4f9b\u4e86\u4e00\u7ec4\u7c7b\uff0c\u7528\u4e8e\u516c\u5f00 JSON \u5e8f\u5217\u5316\u7684\u65b9\u6cd5\u548c \u53cd\u5e8f\u5217\u5316\u3002\u4e0b\u8868\u63cf\u8ff0\u4e86\u53ef\u7528\u7684\u7c7b\u3002","og_url":"http:\/\/www.ponybai.com\/?p=3761","og_site_name":"\u767d\u767d\u968f\u7b14","article_published_time":"2023-12-25T13:34:01+00:00","article_modified_time":"2023-11-27T13:40:49+00:00","og_image":[{"width":1552,"height":285,"url":"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/11\/json.png","type":"image\/png"}],"author":"ponybai","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"ponybai","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/www.ponybai.com\/?p=3761#article","isPartOf":{"@id":"http:\/\/www.ponybai.com\/?p=3761"},"author":{"name":"ponybai","@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883"},"headline":"JSON \u652f\u6301","datePublished":"2023-12-25T13:34:01+00:00","dateModified":"2023-11-27T13:40:49+00:00","mainEntityOfPage":{"@id":"http:\/\/www.ponybai.com\/?p=3761"},"wordCount":168,"publisher":{"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883"},"keywords":["Apex Json"],"articleSection":["Apex \u5f00\u53d1\u4eba\u5458\u6307\u5357"],"inLanguage":"zh-Hans"},{"@type":"WebPage","@id":"http:\/\/www.ponybai.com\/?p=3761","url":"http:\/\/www.ponybai.com\/?p=3761","name":"JSON \u652f\u6301 - \u767d\u767d\u968f\u7b14","isPartOf":{"@id":"http:\/\/www.ponybai.com\/#website"},"datePublished":"2023-12-25T13:34:01+00:00","dateModified":"2023-11-27T13:40:49+00:00","description":"Apex \u4e2d\u7684 JavaScript \u5bf9\u8c61\u8868\u793a\u6cd5 \uff08JSON\uff09 \u652f\u6301\u53ef\u5b9e\u73b0 Apex \u7684\u5e8f\u5217\u5316 \u5bf9\u8c61\u8f6c\u6362\u4e3aJSON\u683c\u5f0f\uff0c\u5e76\u5bf9\u5e8f\u5217\u5316\u7684JSON\u5185\u5bb9\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\u3002Apex \u63d0\u4f9b\u4e86\u4e00\u7ec4\u7c7b\uff0c\u7528\u4e8e\u516c\u5f00 JSON \u5e8f\u5217\u5316\u7684\u65b9\u6cd5\u548c \u53cd\u5e8f\u5217\u5316\u3002\u4e0b\u8868\u63cf\u8ff0\u4e86\u53ef\u7528\u7684\u7c7b\u3002","breadcrumb":{"@id":"http:\/\/www.ponybai.com\/?p=3761#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.ponybai.com\/?p=3761"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.ponybai.com\/?p=3761#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"http:\/\/www.ponybai.com\/"},{"@type":"ListItem","position":2,"name":"JSON \u652f\u6301"}]},{"@type":"WebSite","@id":"http:\/\/www.ponybai.com\/#website","url":"http:\/\/www.ponybai.com\/","name":"\u767d\u767d\u968f\u7b14","description":"Salesforce\u5b98\u65b9\u8bb2\u5e08","publisher":{"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.ponybai.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883","name":"ponybai","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/image\/","url":"http:\/\/www.ponybai.com\/wp-content\/uploads\/2025\/03\/cropped-Ihsans-WeChatQR.jpg","contentUrl":"http:\/\/www.ponybai.com\/wp-content\/uploads\/2025\/03\/cropped-Ihsans-WeChatQR.jpg","width":248,"height":248,"caption":"ponybai"},"logo":{"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/121.37.188.161"],"url":"http:\/\/www.ponybai.com\/?author=1"}]}},"_links":{"self":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts\/3761","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3761"}],"version-history":[{"count":1,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts\/3761\/revisions"}],"predecessor-version":[{"id":3763,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts\/3761\/revisions\/3763"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/media\/3762"}],"wp:attachment":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3761"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}