0

I have the following JSON File:

   "fields": {
        "x1": {
            "name": "AnExteremLongName"
        },
        "x2": {
            "name": "AnotherExteremLongName"
        },
    },"row": [
        {
            "x1": {
                "name":"Some random Text"
            },
            "x2": {
                "name":"Other random Text"
            }
        }, ....

This is basically a table and to reduce the size of the Json file, the names are extraced into this x values.

I want to get the the Value of "AnExteremLongName" so I have to first get the representive X value. How can I do this without reading all varibles and store them into a "Hashmap"

So basically something like:

String getParamNamebyValue(String ParamValue);
2
  • I suppose you'll have to iterate, as this is backwards from how it's designed to work. Imagine you just have a phonebook and a certain number, and you need to look up the name associated with that number. It's kinda like that. Commented Aug 23, 2011 at 12:21
  • @Stefan: what would you exactly expect as the return value of getParamNamebyValue("AnExteremLongName")? "fields.x1"? And what if "AnExteremLongName" appears multiple times in the json string? Commented Aug 23, 2011 at 13:07

1 Answer 1

2

You'll have to iterate through the object properties using for in and compare them. But it is not really fast and I would not recommend it.

Something like this.

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

3 Comments

yes, I think so too... would it be better to send the list without this optimization, even if the paramternames could take >10 characters?
I'd suggest you don't optimize this in your code but rather just compress the Json you send out. If those things repeat themselves a lot the compression will bring the size down..
+1 for compression. JSON has a quite light footprint so if it's still too large you'll have to work on your data and make use of hashing, pagination to optimize your application.

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.