JSON String inside a JSON

前端 未结 3 863
忘了有多久
忘了有多久 2021-01-01 17:04

I want to create a JSON string inside a JSON request. Here is my code,

Fiddle

JS

var x = {
    a: 1,
    b: \'a sample text\         


        
3条回答
  •  天涯浪人
    2021-01-01 17:17

    Well, this may not be helpful. But, I ran into an issue where the JSON string inside a JSON had no property. I was able to parse the JSON string doing the following:

    //Return from remote php request {'{"firsttest": 0, ""scndTest": 1"}'};
    // How to access 
    let data = Object.Keys(jsonWJsonString)[0];
    let justJSONValue = JSON.parse(data);
    

    this works because there is no object property to reference so an index value can be used; which gives us the JSONString. Hope that helped anyone. Cheers

提交回复
热议问题