How to Remove Square bracket from JSON

后端 未结 3 960
甜味超标
甜味超标 2020-12-10 16:01

I have one json string like below

[

    {
        \"Name\": \"TEST\",
        \"deviceId\": \"\",
        \"CartId\": \"\",
        \"timestamp\": 138319726         


        
相关标签:
3条回答
  • 2020-12-10 16:11
    var tmpStr = '[    
        {
            "Name": "TEST",
            "deviceId": "",
            "CartId": "",
            "timestamp": 1383197265540,
            "FOOD": [],
            "City": "LONDON CA"
         }
    
    ]';
    
    var newStr = tmpStr.substring(1, tmpStr.length-1);
    

    See this codepen example

    0 讨论(0)
  • 2020-12-10 16:16

    Use this when you return:

    return properties[0];
    

    Or

    var data = [
    
    {
        "Name": "TEST",
        "deviceId": "",
        "CartId": "",
        "timestamp": 1383197265540,
        "FOOD": [],
        "City": "LONDON CA"
     }
    
    ]; // Or whatever the Json is
    data = data[0];
    

    Or if you're accessing the json via another object

    var data = jsonObj[0];
    
    0 讨论(0)
  • 2020-12-10 16:21

    Try This:

    var A = [{}]; var B = {}; A = [
    
        {
            "Name": "TEST",
            "deviceId": "",
            "CartId": "",
            "timestamp": 1383197265540,
            "FOOD": [],
            "City": "LONDON CA"
         }
    
    ]
    
    B = A[0]; console.log(B); //required output
    
    0 讨论(0)
提交回复
热议问题