How to get json key and value in javascript?

前端 未结 8 1351
暗喜
暗喜 2020-11-28 06:02

I am returning a json as shown below

{\"name\": \"\", \"skills\": \"\", \"jobtitel\": \"Entwickler\", \"res_linkedin\": \"GwebSearch\"}

I a

相关标签:
8条回答
  • 2020-11-28 06:05

    It looks like data not contains what you think it contains - check it.

    let data={"name": "", "skills": "", "jobtitel": "Entwickler", "res_linkedin": "GwebSearch"};
    
    console.log( data["jobtitel"] );
    console.log( data.jobtitel );

    0 讨论(0)
  • 2020-11-28 06:08

    you have parse that Json string using JSON.parse()

    ..
    }).done(function(data){
        obj = JSON.parse(data);
        alert(obj.jobtitel);
    });
    
    0 讨论(0)
  • 2020-11-28 06:19

    A simple approach instead of using JSON.parse

     success: function(response){
         var resdata = response;
         alert(resdata['name']);
    }
    
    0 讨论(0)
  • 2020-11-28 06:21

    http://jsfiddle.net/v8aWF/

    Worked out a fiddle. Do check it out

    (function() {
        var oJson = {
            "name": "", 
            "skills": "", 
            "jobtitle": "Entwickler", 
            "res_linkedin": "GwebSearch"
        }
        alert(oJson.jobtitle);
    })();
    
    0 讨论(0)
  • 2020-11-28 06:23
    var data = {"name": "", "skills": "", "jobtitel": "Entwickler", "res_linkedin": "GwebSearch"}
    
    var parsedData = JSON.parse(data);
    alert(parsedData.name);
    alert(parsedData.skills);
    alert(parsedData.jobtitel);
    alert(parsedData.res_linkedin);
    
    0 讨论(0)
  • 2020-11-28 06:25
    //By using jquery json parser    
    var obj = $.parseJSON('{"name": "", "skills": "", "jobtitel": "Entwickler", "res_linkedin": "GwebSearch"}');
    alert(obj['jobtitel']);
    
    //By using javasript json parser
    var t = JSON.parse('{"name": "", "skills": "", "jobtitel": "Entwickler", "res_linkedin": "GwebSearch"}');
    alert(t['jobtitel'])
    

    Check this jsfiddle

    As of jQuery 3.0, $.parseJSON is deprecated. To parse JSON strings use the native JSON.parse method instead.

    Source: http://api.jquery.com/jquery.parsejson/

    0 讨论(0)
提交回复
热议问题