Ask a regular

Source: Internet
Author: User
Ask a regular:
The data is sometimes like this:
["Two S", "Li S", "Wang S", "one S"]
[{"DEVID": 1, "area": "Guangzhou", "USERID": null, "USERNAME": "King S", "Devtype": null, "Devname": "IPad2", "Devimei": " IPAD2346523985687 "," isusable ": 1," binddate ":" 2013-05-13t09:05:33 "," UPDATEUSER ": null," UpdateTime ":" 0001-01-01t00 : 00:00 "}]
Or
["Two S", "Li S", "Wang S", "one S"]
Or
[{"DEVID": 1, "area": "Guangzhou", "USERID": null, "USERNAME": "King S", "Devtype": null, "Devname": "IPad2", "Devimei": " IPAD2346523985687 "," isusable ": 1," binddate ":" 2013-05-13t09:05:33 "," UPDATEUSER ": null," UpdateTime ":" 0001-01-01t00 : 00:00 "}]

How do you judge in your code whether this character contains [?].
Success:function (returnvalue) {                    //select                    var returnjson = returnvalue.split (' [')] [0] + '] ';                    var returnValue1 = ' [' + returnvalue.split ('] [') [1];

This can sometimes be an error, I want to use a regular to determine the existence of the character [to intercept the data


Reply to discussion (solution)

IndexOf () method

Isn't that JSON? Why do you want a string intercept?

Isn't that JSON? Why do you want a string intercept?
["Two S", "Li S", "Wang S", "one S") This paragraph should be taken out separately put in the drop-down box

[{"DEVID": 1, "area": "Guangzhou", "USERID": null, "USERNAME": "King S", "Devtype": null, "Devname": "IPad2", "Devimei": " IPAD2346523985687 "," isusable ": 1," binddate ":" 2013-05-13t09:05:33 "," UPDATEUSER ": null," UpdateTime ":" 0001-01-01t00 : 00:00 "}]
This section is going to form a form

Sometimes there are 2 pieces of data, sometimes only the latter. So I want to determine if there are 2 pieces of data. How do you write it?

IndexOf () method

var str= "Hello world!" A value greater than 0, with 2 segments of data, is intercepted. Otherwise it is a piece of data, the direct assignment does not intercept. Is that what it means? if (Returnvalue.indexof ("[") > 0) {   var Returnjson = Returnvalue.split ('] [') [0] + '] ';   var returnValue1 = ' [' + returnvalue.split ('] [') [1]; else{  var returnvalue;}

IndexOf () method

I tested it this way, var = "[ReturnValue]" When it is OK, but var returnvalue = "[1]";
  • 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.