Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8102999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:23:45+00:00 2026-06-05T23:23:45+00:00

I have a JSON question. The following code is where the error occurs. I

  • 0

I have a JSON question.

The following code is where the error occurs. I have verified the result string is the following.

{"name":"test", "num1":1.0, "num2":2.0}

and this is the code.

byte[] raw = new byte[1536];

try{

   DatagramPacket packet = new DatagramPacket( raw, raw.length ); 
   mSocket.receive( packet ); //Multicast Socket declared in another part of the program
   String result = new String(packet.getData(), 0, packet.getLength());
   JSONObject jObj = new JSONObject(result);
   String name = jObj.getString("name");
}
catch (JSONException e){

}
catch(Exception eX){

}

However I get a JSONException with the following error.

No value for name.

Is there something wrong with my JSON syntax?

Thanks,

This is what the string shows me

This is what the json object shows me

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:23:46+00:00Added an answer on June 5, 2026 at 11:23 pm

    It looks like there is an issue with the encoding. Have you tried specifying UTF-8

    String response = new String(packet.getData(), 0, packet.getLength(), "UTF-8");
    

    I’m not sure what the issue could be. The rest of your code looks correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: NSMutableDictionary *jsonObj = [parser objectWithString:json_string error:nil]; NSString *test =
ok i have this following code that parses JSON from an ajax response using
I have Json returning as the following: [{CreatedBy:GIS_DB,CreatedDate:3/8/2012 10:44:00 AM,Id:39,ModifiedBy:,ModifiedDate:,Name:CF-39,StatusId:1,TrailCoordinates:[{CreatedBy:GIS_DB,CreatedDate:3/8/2012 10:44:00 AM,Id:1637,Latitude:32.76004207,Longitude:-97.34006853,ModifiedBy:,ModifiedDate:,SortOrder:1,TrailId:39},{CreatedBy:GIS_DB,CreatedDate:3/8/2012 10:44:00 AM,Id:1638,Latitude:32.76004333,Longitude:-97.34012121,ModifiedBy:,ModifiedDate:,SortOrder:2,TrailId:39}]},{CreatedBy:GIS_DB,CreatedDate:3/8/2012
I have an json output of the following (ignore the escape characters) {\sEcho\:1,\iTotalRecords\:10,\iTotalDisplayRecords\:10,\aaData\:[{\Job\:\developer\,\Name\:\kurt\},{\Job\:\plumber\,\Name\:\john\}]} which
This has to be a Jquery question. The following code is returning zero. When
I have a similar problem to a question over here with the following code:
I have the following // this code is inside cellForRowAtIndexPath for a TableViewController id
I have following code. Damn, I stuck with this, I know that is very
I have a JSON feed that I'm parsing. Here's the following code samples: JSON
I have the following $.post() function that expects JSON as its return value. $.post($(this).attr(action),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.