Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SimonFo · Aug 05, 2014 at 07:39 PM · objectsyntax-errorsyntax

Problem syntax C# => JS

Hello,

I have this code in C# :

 public static void Main(string[] args)
 {
     XmlSerializer deserializer = new XmlSerializer(typeof(Address));
     TextReader reader = new StreamReader(@"D:\myXml.xml");
     object obj = deserializer.Deserialize(reader);
     Address XmlData = (Address)obj;
     reader.Close();
 }


And i made it in JS :

 public static function Main(args :String) {
     var deserializer : XmlSerializer = new XmlSerializer(typeof(Adress));     
     var reader : TextReader = new StreamReader(Application.dataPath +"XML.xml");     
     var obj : object = deserializer.Deserialize(reader);
     var XmlData : Address =(Address)obj;     
     reader.Close(); 
 }



But this ligne give me an error:

 var XmlData : Address = (Address)obj;


Assets/Script/Adress.js(18,50): UCE0001: ';' expected. Insert a semicolon at the end.

I don't understand why, please someone for help me ?

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image $$anonymous$$ · Aug 05, 2014 at 07:46 PM 0
Share

Will something change if you declare var XmlData : Adress; on one line and assign its value on another line ins$$anonymous$$d of doing it all in one line?

avatar image Landern · Aug 05, 2014 at 07:51 PM 0
Share

@ZyTr0N, youre right, the unity script is called Adress.js and if the class wasn't specified, it would generate out to a type called Adress, plus you can see where deserializer is declared it uses Adress and not Address.

avatar image SimonFo · Aug 06, 2014 at 09:43 AM 0
Share

Thank you ! But have new problem now,

Assets/Address.js(17,27): BCE0018: The name 'object' does not denote a valid type ('not found'). Did you mean 'UnityEditorInternal.Object$$anonymous$$emoryInfo'?

 import System.Collections.Generic;
 import System.Xml;
 import System.IO;
 import System.Xml.Serialization;
 
 
 public class Address
 {
     public var HouseNo : int;
     public var StreetName : String;
     public var City : String;
     
     public static function $$anonymous$$ain(args : String)
     {
     var deserializer : XmlSerializer = new XmlSerializer(typeof(Address));
         var reader : TextReader = new StreamReader(Application.dataPath + "X$$anonymous$$L.xml");
         var obj : object = deserializer.Deserialize(reader);
         var XmlData : Address;
         XmlData = obj as Address;
         reader.Close();
     }
 }

avatar image HarshadK · Aug 06, 2014 at 09:52 AM 0
Share

You need 'Object'.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kiwasi · Aug 05, 2014 at 07:42 PM

 var XmlData : Address = obj as Address;
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Stuff-is-going-wacky! Checklist - Compiler-Errors, Syntax-Errors 5 Answers

Error: Cannot cast from source type to destination type 2 Answers

Error CS8025? 1 Answer

How Do I deActivate One Sphere ? 1 Answer

Literal Notation Object Creation in unity? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges