JSON object and JSON string

Source: Internet
Author: User

JSON object and JSON string

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Output:

Aaberg, Jesper, 555-0100,555-0120

Aaberg, Jesper, 555-0100,555-0120


**************************************** **************************************** ****

Example of receiving a JSON object on the front-end page:

<Script> sendRecord ('1'); function sendRecord (record) {var req = {user_id: <? Php echo $ userId;?>, Record: record,} $. ajax ({url: "/3G/wall/ajax_send_record/", type: "post", data: req, dataType: "JSON ", // The returned data is in the JSON object success: function (res) {if (res. result = 1) {// because the passed object is a JSON object, no JSON is needed. parse () parses alert ('11');} else if (res. result = 2) {alert ('22');} else if (res. result = 3) {alert ('33') ;}, error: function () {alert ('error000'); console. log (this) ;}}) ;}</script>


<?php    function ajax_send_record()    {        $record = $_POST('record');        if ($record==1) {                    $json['result'] = 1;                    }elseif($record==2){$json['result'] = 2;}elseif(elseif($record==3){$json['result'] = 3;}$json = json_encode($json);echo $json;    }?>



Convert a json string to an object using jsonnet

Based on your json data, you can convert the data as follows:

Call the DeJson method in the Custom class to input a json string to return the object.




Java: converts a json string to a json object.

Hello !!
Import java. io. *; import org. json. *; public class Demo {public static void main (String [] args) throws Exception {String str = "{\" brand_no \ ": \" jycy, sy \", \ "unit_rank \": \ "2 \", \ "package \": \ "2 \"} "; JSONObject obj = new JSONObject (str); System. out. println (obj); System. out. println (obj. get ("brand_no"); // "jycy, sy "}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.