{"id":230,"date":"2020-12-06T15:24:39","date_gmt":"2020-12-06T09:54:39","guid":{"rendered":"https:\/\/selfimagination.in\/tips\/?p=230"},"modified":"2021-10-19T15:30:05","modified_gmt":"2021-10-19T10:00:05","slug":"json-encode","status":"publish","type":"post","link":"https:\/\/selfimagination.in\/tips\/json-encode\/","title":{"rendered":"JSON (PHP, JavaScript)"},"content":{"rendered":"\n<p class=\"wp-block-zozuk-wphindi\">JSON\u00a0 :\u00a0 JavaScript Object Notation\u00a0 \u0915\u093e \u0936\u093e\u0930\u094d\u091f \u092b\u0949\u0930\u094d\u092e \u0939\u0948\u0902,  \u091c\u092c \u092d\u0940 \u0939\u092e\u0947\u0902 \u0915\u094b\u0908 \u0921\u093e\u091f\u093e carry\u00a0 \u0915\u0930\u0928\u093e \u0939\u094b\u0924\u093e \u0939\u0948\u0902 \u0924\u094b \u091c\u0938\u094b\u0902 \u0938\u092c\u0938\u0947 \u092c\u095d\u093f\u092f\u093e \u092b\u0949\u0930\u094d\u092e\u0947\u091f \u0939\u094b\u0924\u093e \u0939\u0948\u0902 \u0921\u093e\u091f\u093e \u0915\u094b carry\u00a0 \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f,  \u092f\u0939\u093e\u0901 \u092a\u0930 \u0939\u092e\u0928\u0947 \u090f\u0915 example\u00a0 \u0926\u093f\u092f\u093e \u0939\u0948\u0902 \u091c\u093f\u0938\u092e\u0947 \u0939\u092e\u0928\u0947 \u0928\u0902\u092c\u0930 \u0914\u0930 \u0938\u094d\u091f\u094d\u0930\u093f\u0902\u0917 \u0915\u0947 \u0921\u093e\u091f\u093e \u0915\u094b \u0915\u0948\u0938\u0947 json\u00a0\u092e\u0947\u0902 \u092a\u093e\u0938 \u0915\u093f\u092f\u093e \u091c\u093e\u0924\u093e \u0939\u0948\u0902, \u0909\u0938\u0947 \u0926\u093f\u0916\u093e\u092f\u093e \u0939\u0948\u0902 ,<\/p>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\">JSON \u090f\u0915 \u0910\u0938\u093e Format \u0939\u0948\u0902 \u091c\u093f\u0938\u092e\u0947 \u0939\u092e \u0906\u0938\u093e\u0928\u0940 \u0938\u0947 \u0921\u093e\u091f\u093e \u0915\u094b \u0909\u0928\u0915\u0947 Name \u0915\u0947 \u0938\u093e\u0925 String Format \u092e\u0947\u0902 \u092d\u091c\u0947 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902 \u0914\u0930 \u092b\u093f\u0930 \u0909\u0938\u0947 \u091c\u0939\u093e \u092a\u0930 \u092d\u0940 Receive \u0915\u0930\u0928\u093e \u0939\u0948\u0902 , Receive \u0915\u0930 \u090f\u0915 Object \u092c\u0928\u093e \u0915\u0930 Value \u0915\u094b Get \u0915\u0930 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902, \u0906\u0907\u092f\u0947 \u0939\u092e \u0907\u0938\u0915\u0947 \u0938\u092d\u0940 \u0909\u092a\u092f\u094b\u0917 \u0915\u094b \u0938\u092e\u091d\u0924\u0947 \u0939\u0948 \u0964<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">PHP Array to JSON : PHP \u092e\u0947\u0902 array \u0938\u0947 JSON \u092e\u0947\u0902 \u092c\u0926\u0932\u0928\u093e<\/h2>\n\n\n\n<p>\u091c\u092c \u0939\u092e \u0915\u093f\u0938\u0940 PHP Page \u0915\u094b Ajax \u0926\u094d\u0935\u093e\u0930\u093e Call \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0924\u092c \u0939\u092e\u0947 JSON \u0915\u0940 \u091c\u0930\u0942\u0930\u0924 \u0939\u094b\u0924\u0940 \u0939\u0948\u0902 \u0924\u093e\u0915\u093f \u0939\u092e \u0909\u0938\u0947 \u091c\u0939\u093e \u0938\u0947 \u092d\u0940 Call \u0915\u093f\u092f\u093e \u0939\u0948\u0902 \u0935\u0939\u093e \u092a\u0930 Receive \u0915\u0930 \u0909\u0938\u0915\u0940 \u0935\u0948\u0932\u094d\u092f\u0942 \u0915\u094b Decode \u0915\u0930 \u0909\u092a\u092f\u094b\u0917 \u092e\u0947 \u0932\u0947 \u0938\u0915\u0947 <\/p>\n\n\n\n<p>\u0928\u093f\u092e\u094d\u0928 \u0909\u0926\u093e\u0939\u0930\u0923 \u0938\u0947 \u0906\u092a \u0938\u092e\u091d \u0938\u0915\u0924\u0947 \u0939\u0948\u0902 \u0915\u0940 \u0915\u093f\u0938 \u092a\u094d\u0930\u0915\u093e\u0930 \u0939\u092e Array \u092e\u0947 \u0935\u0948\u0932\u094d\u092f\u0942 \u0938\u0947\u091f \u0915\u0930 \u0909\u0938\u0915\u094b JSON \u092e\u0947 \u092c\u0926\u0932 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902 \u0964 <\/p>\n\n\n\n<pre title=\"JSON Encode\" class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php \n\n$array_m['a'] = 1;\n$array_m['b'] = \"Two\";\n$array_m['c'] = 3;\n$array_m['d'] = \"Four\";\n\n$myJSON = json_encode($array_m);\necho \"Return Number Values :\" . $myJSON;\n\/\/{\"a\":1,\"b\":\"Two\",\"c\":3,\"d\":\"Four\"}\n\n?><\/code><\/pre>\n\n\n\n<p class=\"wp-block-zozuk-wphindi\">\u0909\u092a\u0930\u094b\u0915\u094d\u0924 \u0909\u0926\u093e\u0939\u0930\u0923 \u092e\u0947 \u092f\u0926\u093f \u0915\u0947\u0935\u0932 \u0906\u092a  $myJSON  \u0915\u094b echo \u0915\u0930 \u0926\u0947\u0902\u0917\u0947 \u0924\u094b \u0907\u0938\u0947 \u091c\u0939\u093e \u0938\u0947 \u092d\u0940 Call \u0915\u093f\u092f\u093e \u0939\u0948\u0902 \u0935\u0939 \u092a\u0930 Receive \u0915\u0930 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902 \u0964 <\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u0939\u092e\u093e\u0930\u0947 \u0905\u0928\u094d\u092f \u0906\u0930\u094d\u091f\u093f\u0915\u0932<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/selfimagination.in\/tips\/learn-c-basic-n-advance\/\">Learn C \u2013 \u0939\u093f\u0902\u0926\u0940 \u092e\u0947\u0902<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/mysql-aggregate-function-in-hindi\/\">MySQL Aggregate Function in Hindi<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/mysql-sys-exec-example-with-trigger\/\">MySQL SYS_EXEC Example With Trigger<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/get-post-method\/\">GET &amp; POST Method | Difference Between GET &amp; POST<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/php-validation-filter-var-preg_match\/\">PHP Validation | filter_var | preg_match<\/a><\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">JSON String using JavaScript : JavaScript \u0938\u0947 JSON \u092c\u0928\u093e\u0928\u093e <\/h2>\n\n\n\n<p>\u091c\u092c \u0939\u092e\u0947 JavaScript \u092e\u0947 \u0938\u0947 \u0935\u0948\u0932\u094d\u092f\u0942 \u0915\u094b JSON \u0915\u0947 format \u092e\u0947 \u092a\u0939\u0941\u091a\u093e\u0928\u093e \u0939\u094b \u091c\u092c \u092d\u0940 \u0939\u092e \u0907\u0938\u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">\/\/1. Single Array Value\r\nvar Col1 = JSON.stringify({\"val1\":1001,\"val2\":1002}); \r\n\r\n\/\/2. Multiple Array Value\r\nvar Col2 = [];\r\nCol2.push({\"val1\":2001,\"val2\":2002, \"val3\":2003}); \r\nCol2.push({\"val1\":3001,\"val2\":3002, \"val3\":3003}); \r\n\r\nvar ColStr = JSON.stringify(Col2);\r\n\r\n$.ajax({\r\n         url: 'yoururl.php',\r\n         type: 'post',\r\n         data: {p1: Col1, p2:ColStr },\r\n         success: function(response){        \r\n         }     \r\n});<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>1. \u092a\u0939\u0932\u0940 \u0932\u093e\u0907\u0928 \u092e\u0947 \u0939\u092e\u0928\u0947 \u090f\u0915 Variable \u092e\u0947 Multiple Value Send \u0915\u0940 \u0939\u0948\u0902 \u0964 <\/li><li>2. \u0926\u0942\u0938\u0930\u0947 Example \u092e\u0947 \u0939\u092e\u0928\u0947 \u090f\u0915 Single Array \u092e\u0947 Multiple Array send \u0915\u093f\u090f \u0939\u0948\u0902 \u0964 <\/li><\/ul>\n\n\n\n<p>\u0907\u0928 \u0926\u094b\u0928\u094b\u0902 \u0915\u094b PHP \u092e\u0947 Receive \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0915\u0941\u091b \u0907\u0938 \u092a\u094d\u0930\u0915\u093e\u0930 \u0938\u0947 Code \u0932\u093f\u0916\u0947\u0902\u0917\u0947 \u0964 <\/p>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">JSON String Receive in PHP : PHP \u092e\u0947 JSON String \u0915\u094b Receive \u0915\u0930\u0928\u093e <\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u091c\u094b \u0909\u092a\u0930\u094b\u0915\u094d\u0924 Example \u0938\u0947 \u0939\u092e\u0928\u0947 JavaScript \u0938\u0947 JSON send \u0915\u0940 \u0939\u0948\u0902 \u0909\u0928\u094d\u0939\u0947 \u0907\u0938 Example \u0938\u0947 Receive \u0915\u0930\u0928\u0947 \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947 \u092c\u0924\u093e\u092f\u093e \u0917\u092f\u093e \u0939\u0948\u0902 \u0964 <\/li><li>\u0907\u0938 Example \u092e\u0947 \u0939\u092e\u0928\u0947 Single Value \u0913\u0930 Multiple Value \u0926\u094b\u0928\u094b\u0902 \u0915\u094b \u0939\u093f \u0915\u093f\u0938 \u092a\u094d\u0930\u0915\u093e\u0930 \u0938\u0947 Receive \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0909\u0938\u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947 \u092c\u0924\u093e\u092f\u093e \u0939\u0948\u0902 \u0964 <\/li><\/ul>\n\n\n\n<pre title=\"yoururl.php\" class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php \n\n$sVal = $_POST['p1'];      \/\/1. Get Parameter Value \r\n$mVal = $_POST['p2'];\r\n\r\n\/\/2. Single Array Receive\r\n$ObjS = json_decode($sVal);              \r\n$Val1 = $ObjS->val1; \r\n$Val2 = $ObjS->val2;\r\n\r\n\/\/3. Multiple Array Receive\r\n$objM = json_decode($mVal);\r\n\r\nforeach($mVal as $key=>$value)\r\n{\r\n         $col1 = $value->val1;\r\n         $col2 = $value->val2;\r\n         $col3 = $value->val3;\r\n}\n\n?><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>1. \u0938\u092c\u0938\u0947 \u092a\u0939\u0932\u0947 \u0939\u092e\u0928\u0947 \u091c\u094b POST Method \u0938\u0947 Parameter Send \u0915\u093f\u090f \u0939\u0948\u0902 \u0909\u0928\u0915\u094b Receive \u0915\u0930\u0947\u0902\u0917\u0947 \u0964 Receive \u0915\u0930\u0928\u0947 \u0915\u093e \u0924\u0930\u0940\u0915\u093e \u0926\u094b\u0928\u094b\u0902 \u0939\u0940 Case \u092e\u0947 \u090f\u0915 \u091c\u0948\u0938\u093e \u0939\u0940 \u0939\u094b\u0917\u093e \u0964 <\/li><li>2. \u091c\u094b Value Receive \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0909\u0928\u0915\u094b Decode \u0915\u0930\u0928\u093e \u0939\u094b\u0924\u0940 \u0939\u0948\u0902 \u091c\u093f\u0938\u0938\u0947 \u0935\u0939 \u090f\u0915 Object \u092c\u0928 \u091c\u093e\u0924\u0940 \u0939\u0948\u0902 \u0909\u0938\u0915\u0947 \u092c\u093e\u0926 \u0939\u092e object Notation \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930 value \u0915\u094b Get \u0915\u0930 \u0932\u0947\u0924\u0947 \u0939\u0948\u0901 \u0964 <\/li><li>3. \u092f\u0939 \u092a\u0930 \u092d\u0940 \u0939\u092e Value \u0915\u094b Decode \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0909\u0938\u092e\u0947 Multiple Value \u0915\u094b Separate \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f foreach \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u093f\u092f\u093e \u0939\u0948\u0902 \u0939\u0948\u0902 \u0964 <\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u0906\u0936\u093e \u0939\u0948\u0902 \u092e\u0941\u091d\u0947 \u0906\u092a\u0915\u094b JSON \u0938\u0947 \u0938\u0902\u092c\u0902\u0927\u093f\u0924 \u0915\u093e\u0930\u094d\u092f \u091c\u094b \u0915\u0940 \u0939\u092e \u0915\u094b\u0908 \u092d\u0940 Application \u092c\u0928\u093e\u0928\u0947 \u092e\u0947 \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0938\u092e\u091d \u092e\u0947 \u092f\u093e \u0917\u092f\u093e \u0939\u094b\u0917\u093e, \u092b\u093f\u0930 \u092d\u0940 \u092f\u0926\u093f \u0915\u094b\u0908 Doubt \u0939\u094b \u0924\u094b \u0906\u092a \u092e\u0941\u091d\u0947 Comment \u0915\u0930 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902 \u0964 <\/p>\n\n\n\n<p>\u0905\u092a\u0928\u093e \u0915\u0940\u092e\u0924\u0940 \u0938\u092e\u092f \u0926\u0947\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0927\u0928\u094d\u092f\u0935\u093e\u0926 \u0964 <\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n","protected":false},"excerpt":{"rendered":"<p>PHP Array to JSON : PHP \u092e\u0947\u0902 array \u0938\u0947 JSON \u092e\u0947\u0902 \u092c\u0926\u0932\u0928\u093e \u091c\u092c \u0939\u092e \u0915\u093f\u0938\u0940 PHP Page \u0915\u094b Ajax \u0926\u094d\u0935\u093e\u0930\u093e Call \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0924\u092c \u0939\u092e\u0947 JSON \u0915\u0940 \u091c\u0930\u0942\u0930\u0924 \u0939\u094b\u0924\u0940 \u0939\u0948\u0902 \u0924\u093e\u0915\u093f \u0939\u092e \u0909\u0938\u0947 \u091c\u0939\u093e \u0938\u0947 \u092d\u0940 Call \u0915\u093f\u092f\u093e \u0939\u0948\u0902 \u0935\u0939\u093e \u092a\u0930 Receive \u0915\u0930 \u0909\u0938\u0915\u0940 \u0935\u0948\u0932\u094d\u092f\u0942 \u0915\u094b Decode \u0915\u0930 \u0909\u092a\u092f\u094b\u0917 \u092e\u0947 \u0932\u0947 \u0938\u0915\u0947 \u0928\u093f\u092e\u094d\u0928 \u0909\u0926\u093e\u0939\u0930\u0923 \u0938\u0947 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":320,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-230","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2020\/12\/json.png?fit=1091%2C393&ssl=1","_links":{"self":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/comments?post=230"}],"version-history":[{"count":29,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/230\/revisions"}],"predecessor-version":[{"id":4430,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/230\/revisions\/4430"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/media\/320"}],"wp:attachment":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/media?parent=230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/categories?post=230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/tags?post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}