0

Hi how i can parse this json string: {"Error":true, "data":["not available","somethinghere"]}

but that string i get it from an alert like this:

alert(ff.Result.value);

i need to get from that alert just the "not available" from the json string

alexistkd
  • 906
  • 2
  • 14
  • 34
  • possible duplicate of [Safely turning a JSON string into an object](http://stackoverflow.com/questions/45015/safely-turning-a-json-string-into-an-object) – Bergi Jul 05 '12 at 19:02

1 Answers1

2

Most modern browsers support the JSON object:

var errorObject = JSON.parse(ff.Result.value);
alert(errorObject.data[0]);

See Browser-native JSON support (window.JSON)

An example using json2.js:

<script src="https://raw.github.com/douglascrockford/JSON-js/master/json2.js"></script>
<script>
    var errorObject = JSON.parse(ff.Result.value);
    document.getElementById('someId').innerHTML += errorObject.data[0];
</script>
Community
  • 1
  • 1
Sergey Eremin
  • 10,994
  • 2
  • 38
  • 44