0

I have the following JSON:

{
  "responseHeader":{
    "params":{
      "facet":"true",
      "fl":"city",
      "facet.mincount":"1",
      "indent":"on",
      "start":"0",
      "q":["*:*",
        "*:*"],
      "wt":"json",
      "rows":"12"}},
  "response":{"numFound":1,"start":0,"docs":[
      {"city":"lathum"}]
  },
  "facet_counts":{
    "facet_fields":{
      "hasphoto":[
        "true",61,
        "false",5],
      "hasvideo":[
        "false",51,
        "true",15],
      "rating_rounded":[
        "0.0",62,
        "10.0",3,
        "8.0",1]},
    "facet_ranges":{}}}

I wonder if it's possible to select a value based on a property name, in my case, I want to select how many of hasphoto have the value true, which would be 61. Please note that the true value does not necessarily have to be the first listed under hasphoto, true and false are sorted by number of occurences.

I want to get the value directly without having to loop through it....is that possible?

I tried:

response.facet_counts.facet_fields['hasphoto']['true']

and

response.facet_counts.facet_fields.hasphoto['true']

But both return undefined.

1
  • You should probably indicate what language you're using. JSON support in FORTRAN is pretty arcane. Commented Jan 23, 2014 at 22:22

1 Answer 1

1

Arrays are ordered lists, not key-value stores so

response.facet_counts.facet_fields.hasphoto[0] gives you the string "true", response.facet_counts.facet_fields.hasphoto[1] gives you the number 61, etc...

Sign up to request clarification or add additional context in comments.

1 Comment

Hmmm, ok, so I tried inArray this console.log('index of true:' + $.inArray('true', data.facet_counts.facet_fields['hasphoto'])); but that returns 2...do you know why?

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.