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 "}}