0

I must get a value in a json data like in following link: Value in json data (sorry because I can't emb image). I need to get value of "DT sau CK" and I see that it's value is an empty array [ ]. My function is:

function test () {
  api_url = 'https://my url....'
  var result = UrlFetchApp.fetch(api_url);  
  var data = JSON.parse(result);
  var dtt = data['chart']['data'][2]['value'];
  if (dtt == false || dtt.length == 0) {
    dtt = 0;
  } else {
    dtt = data['chart']['data'][2]['value'];
  }
  return Number(dtt)
}
My if "dtt.length == 0" for an emty array. I want it to give me value/number 0 but it always return another number 157548000, something like that, maybe by api_url/server. But i want to get a number "0" result as i saw an empty array. Can anyone help me, thanks a lot and sorry for my bad English.

1
  • You should add a sample of result to your question. The error must lie in the datastructure or how you access it. Commented Nov 20, 2015 at 6:19

2 Answers 2

1

Maybe you can add this to replace empty arrays with '0':

chart.data.forEach(function (item) {
 if (item.value.length===0) {
   item.value=0;
  }
});
Sign up to request clarification or add additional context in comments.

Comments

0

I faced same issue recently, the solution is to just delete empty/extra columns.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.