Category Archives: Code

Code is a question and answer site for professional and enthusiast programmers.

Swap key with value JSON

I have an extremely large JSON object structured like this:

{A : 1, B : 2, C : 3, D : 4}

I need a function that can swap the values with keys in my object and I don’t know how to do it. I would need an output like this:

{1 : A, 2 : B, 3 : C, 4 : D}

Is there any way that I can do this would manually created a new object where everything is swapped?
Thanks

Swap key with value JSON

How to send Json String using REST to java webservice in Parameter in android?

Fiends, i sending JSON String with three parameters to java web service method. but on java side method cant print in console. Please guide me what i have to change from below code?

String json = "";
        HttpParams httpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
        HttpConnectionParams.setSoTimeout(httpParams, 10000);
        HttpClient httpclient = new DefaultHttpClient();

        // Prepare a request object
        HttpPost httpPost = new HttpPost(url);
        HttpGet httpGet = new HttpGet(url);

        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("name", "ghanshyam");
            jsonObject.put("country", "India");
            jsonObject.put("twitter", "ghahhd");

            json = jsonObject.toString();

            StringEntity se = new StringEntity(json);

            se.setContentEncoding("UTF-8");
            se.setContentType("application/json");

            // 6. set httpPost Entity
            System.out.println(json);

            httpPost.setEntity(se);
            httpGet.se
            // 7. Set some headers to inform server about the type of the content
            //httpPost.addHeader( "SOAPAction", "application/json" );
            httpPost.setHeader("Accept", "application/json");
            httpPost.setHeader("Content-type", "application/json");

            //String s = doGet(url).toString();

            Toast.makeText(getApplicationContext(), "Data Sent", Toast.LENGTH_SHORT).show();

read more

Windows PowerShell give password in command Enter-PSSession

I am writing a project where I run a PowerShell script and create a new PSSession as follows:

PowerShell.exe -Command enter-pssession myUser -credential userName

When I run this, it opens a dialog to prompt the user for a password. However, I would prefer for the user to be able to enter the password along with the rest of the above line instead of having to be bothered with the prompt. I’m very new to PowerShell, and everything I’ve found in docs only gives ways to bring the prompt up for the password. Is this something that is possible to accomplish in PowerShell? Thanks!

read more

Debugging error message: "A script on this page is causing Internet Explorer to run slowly"

One of my users is intermittently getting a dialog in IE 8 that says:

A script on this page is causing Internet Explorer to run slowly

This problem has been reported numerous times in the MSDN forums and other places on the web. For example:

So, this question is a duplicate of those and many others. But it is an intentional duplicate, because I don’t think any of those questions were answered in a way that helps a user (developer) to determine precisely what in his scenario causes the dialog to appear.

read more