[removed] Find key and its value in JSON

后端 未结 5 629
暖寄归人
暖寄归人 2021-01-14 01:12

I have a JSON object that is returned in different ways, but always has key. How can I get it?

E.g.

\"Records\": {
    \"key\": \"112\"
         


        
5条回答
  •  南方客
    南方客 (楼主)
    2021-01-14 01:42

    I will not write the code for you but give you an idea may be it will help, First convert JSON object in to string using

    JSON.stringify(obj);
    

    after that search for Key using indexOf() method. Extract previous '{' and Next '}' string and again cast in to JSON object. using

    var obj =  JSON.parse(string);
    

    Then

     var value = obj.key
    

提交回复
热议问题